### Install sebastian/version with Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/version/README.md
Installs the sebastian/version library as a production dependency using Composer.
```shell
composer require sebastian/version
```
--------------------------------
### Install PHP Parser with Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/nikic/php-parser/README.md
Instructions to install the PHP Parser library using Composer, the PHP dependency manager.
```bash
php composer.phar require nikic/php-parser
```
--------------------------------
### Example Output of SebastianBergmann\Version::asString()
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/version/README.md
Shows an example of the string output generated by the asString() method, including release number, commit count, and Git hash.
```text
string(18) "1.0.0-17-g00f3408"
```
--------------------------------
### Install phpunit/php-code-coverage with Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-code-coverage/README.md
Installs the phpunit/php-code-coverage library as a local, per-project dependency using Composer. This is suitable for general project use.
```bash
composer require phpunit/php-code-coverage
```
--------------------------------
### Install Tokenizer Library with Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/theseer/tokenizer/README.md
Add the Tokenizer library as a project dependency using Composer. This includes options for both production and development-time installations. Composer manages project dependencies.
```bash
composer require theseer/tokenizer
```
```bash
composer require --dev theseer/tokenizer
```
--------------------------------
### Install phpunit/php-timer as production dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-timer/README.md
Installs the `phpunit/php-timer` library as a local, per-project dependency using Composer. This is suitable for libraries required in production environments.
```bash
composer require phpunit/php-timer
```
--------------------------------
### Install sebastian/recursion-context as a production dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/recursion-context/README.md
This command installs the sebastian/recursion-context library as a local, per-project dependency. It is suitable for production environments where the library is required for the application's runtime functionality.
```Shell
composer require sebastian/recursion-context
```
--------------------------------
### Install sebastian/version as development dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/version/README.md
Installs the sebastian/version library as a development-time dependency using Composer, typically for running test suites.
```shell
composer require --dev sebastian/version
```
--------------------------------
### Enable BCMath PHP Extension for ArbiMath
Source: https://github.com/shtse8/arbimath/blob/master/README.md
ArbiMath PHP relies on the BCMath extension for its high-precision calculations. This snippet provides an example command for Debian/Ubuntu systems to install and enable the BCMath extension for a specific PHP version. Users should consult their OS or PHP documentation for specific instructions.
```Bash
# Example for PHP 8.0 on Debian/Ubuntu:
sudo apt install php8.0-bcmath
# Or consult your OS/PHP documentation
```
--------------------------------
### Install DeepCopy PHP Library
Source: https://github.com/shtse8/arbimath/blob/master/vendor/myclabs/deep-copy/README.md
Instructions to install the DeepCopy library using Composer, the PHP dependency manager. This command adds the library to your project's dependencies.
```php
composer require myclabs/deep-copy
```
--------------------------------
### Install sebastian/code-unit with Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/code-unit/README.md
Installs the sebastian/code-unit library as a local, per-project production dependency using Composer. This makes the library available for your project's runtime.
```Shell
composer require sebastian/code-unit
```
--------------------------------
### Install sebastian/object-enumerator as a production dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/object-enumerator/README.md
Installs the sebastian/object-enumerator library as a required production dependency using Composer. This command adds the package to your project's composer.json and installs it into the vendor directory, making it available for your application's runtime.
```bash
composer require sebastian/object-enumerator
```
--------------------------------
### Install sebastian/recursion-context as a development dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/recursion-context/README.md
This command installs the sebastian/recursion-context library as a development-time dependency. It is typically used for tools like test suites that are only needed during the development phase and not in production.
```Shell
composer require --dev sebastian/recursion-context
```
--------------------------------
### Install PECL Operator Extension for PHP Operator Overloading
Source: https://github.com/shtse8/arbimath/blob/master/README.md
This optional installation guide outlines the general steps to compile and enable the PECL Operator extension. This extension allows ArbiNumber objects to use standard PHP arithmetic operators (e.g., +, *, **) for a more natural syntax. Note that this process may require manual compilation and system-specific adjustments.
```Bash
# General steps (adapt for your system):
# git clone https://github.com/php/pecl-php-operator
# cd pecl-php-operator && phpize && ./configure && make && sudo make install
# echo "extension=operator.so" | sudo tee /etc/php/8.0/mods-available/operator.ini
# sudo ln -s /etc/php/8.0/mods-available/operator.ini /etc/php/8.0/cli/conf.d/20-operator.ini
# sudo service php8.0-fpm reload # If using FPM
```
--------------------------------
### Install phpunit/php-timer as development dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-timer/README.md
Installs the `phpunit/php-timer` library as a development-time dependency using Composer. This is ideal for tools like test suites that are only needed during development.
```bash
composer require --dev phpunit/php-timer
```
--------------------------------
### Install sebastian/exporter with Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/exporter/README.md
Instructions for adding the sebastian/exporter library as a project dependency using Composer. Includes commands for both production and development-only dependencies.
```Shell
composer require sebastian/exporter
```
```Shell
composer require --dev sebastian/exporter
```
--------------------------------
### Install PHPUnit using PHAR
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/phpunit/README.md
This snippet demonstrates how to download and verify the PHPUnit PHAR (PHP Archive) file. Replace 'X.Y' with the desired PHPUnit version.
```bash
$ wget https://phar.phpunit.de/phpunit-X.Y.phar
$ php phpunit-X.Y.phar --version
```
--------------------------------
### Install ArbiMath PHP Library via Composer
Source: https://github.com/shtse8/arbimath/blob/master/README.md
This command installs the ArbiMath PHP library into your project using Composer, the standard dependency manager for PHP. It adds shtse8/arbimath to your project's composer.json and downloads the necessary files.
```Bash
composer require shtse8/arbimath
```
--------------------------------
### Compare PHP Versions with Pre-release Labels
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phar-io/version/README.md
This example shows how the `PharIo\Version\Version` class handles comparisons when versions include pre-release labels. It demonstrates that pre-release versions are correctly ordered, allowing for accurate comparison of alpha, beta, or release candidate versions.
```php
$leftVersion = new PharIo\Version\Version('3.0.0-alpha.1');
$rightVersion = new PharIo\Version\Version('3.0.0-alpha.2');
$leftVersion->isGreaterThan($rightVersion); // false
$rightVersion->isGreaterThan($leftVersion); // true
```
--------------------------------
### PHP DeepCopy: Running Unit Tests
Source: https://github.com/shtse8/arbimath/blob/master/vendor/myclabs/deep-copy/README.md
This snippet provides the command line instruction to execute the unit tests for the DeepCopy library. It assumes that PHPUnit is installed as a Composer dependency and its executable is located in the `vendor/bin` directory.
```php
vendor/bin/phpunit
```
--------------------------------
### Install sebastian/comparator PHP library via Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/comparator/README.md
Installs the `sebastian/comparator` library as a production dependency using Composer. This makes the library available for your project's runtime operations.
```Shell
composer require sebastian/comparator
```
--------------------------------
### Install sebastian/object-reflector as a production dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/object-reflector/README.md
Installs the sebastian/object-reflector library as a required dependency for your project using Composer. This is suitable for libraries needed in production environments.
```Bash
composer require sebastian/object-reflector
```
--------------------------------
### Install sebastian/object-reflector as a development dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/object-reflector/README.md
Installs the sebastian/object-reflector library as a development-time dependency using Composer. This is typically used for tools required during development, such as testing frameworks.
```Bash
composer require --dev sebastian/object-reflector
```
--------------------------------
### Install Production Dependency with Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/global-state/README.md
Installs the `sebastian/global-state` library as a required production dependency using Composer. This makes the library available for your application's runtime environment.
```bash
composer require sebastian/global-state
```
--------------------------------
### Install sebastian/comparator as development dependency via Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/comparator/README.md
Installs the `sebastian/comparator` library as a development-time dependency using Composer. This is typically used for tools like test suites that are not needed in production.
```Shell
composer require --dev sebastian/comparator
```
--------------------------------
### Install PHP Side-effects Detector with Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/staabm/side-effects-detector/README.md
Use Composer to add the `staabm/side-effects-detector` library to your PHP project. This command fetches and installs the necessary package, making the detector available for use.
```bash
composer require staabm/side-effects-detector
```
--------------------------------
### Install phpunit/php-code-coverage as dev dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-code-coverage/README.md
Installs the phpunit/php-code-coverage library as a development-time dependency using Composer. This is ideal when the library is only needed for development tasks, such as running a project's test suite.
```bash
composer require --dev phpunit/php-code-coverage
```
--------------------------------
### Install Development Dependency with Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/global-state/README.md
Installs the `sebastian/global-state` library as a development-time dependency using Composer. This is suitable for tools like test suites that are not needed in production environments.
```bash
composer require --dev sebastian/global-state
```
--------------------------------
### Install sebastian/complexity as Production Dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/complexity/README.md
Installs the sebastian/complexity library as a production dependency in your PHP project using Composer. This makes the library available for your application's runtime.
```Shell
composer require sebastian/complexity
```
--------------------------------
### Install sebastian/code-unit as a development dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/code-unit/README.md
Installs the sebastian/code-unit library as a development-time dependency using Composer. This is typically used for tools like test suites that are only needed during development.
```Shell
composer require --dev sebastian/code-unit
```
--------------------------------
### Install sebastian/environment as Production Dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/environment/README.md
Installs the sebastian/environment library as a required production dependency for your project using Composer. This makes the library available for your application's runtime.
```Shell
composer require sebastian/environment
```
--------------------------------
### Install sebastian/environment as Development Dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/environment/README.md
Installs the sebastian/environment library as a development-time dependency using Composer. This is suitable for tools or test suites that are only needed during development.
```Shell
composer require --dev sebastian/environment
```
--------------------------------
### Example AST Dump Output
Source: https://github.com/shtse8/arbimath/blob/master/vendor/nikic/php-parser/README.md
An example of the Abstract Syntax Tree (AST) structure generated by the PHP Parser for a simple PHP function, showing the hierarchical representation of code elements.
```text
array(
0: Stmt_Function(
attrGroups: array(
)
byRef: false
name: Identifier(
name: test
)
params: array(
0: Param(
attrGroups: array(
)
flags: 0
type: null
byRef: false
variadic: false
var: Expr_Variable(
name: foo
)
default: null
)
)
returnType: null
stmts: array(
0: Stmt_Expression(
expr: Expr_FuncCall(
name: Name(
name: var_dump
)
args: array(
0: Arg(
name: null
value: Expr_Variable(
name: foo
)
byRef: false
unpack: false
)
)
)
)
)
)
)
```
--------------------------------
### Install sebastian/diff with Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/diff/README.md
Instructions for adding the sebastian/diff library as a project dependency using Composer, including a development-only option for test suites.
```shell
composer require sebastian/diff
```
```shell
composer require --dev sebastian/diff
```
--------------------------------
### Example XML Output from PHP Tokenizer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/theseer/tokenizer/README.md
Illustrates the XML structure generated by the Tokenizer library. It shows how PHP source code lines and individual tokens (e.g., T_OPEN_TAG, T_DECLARE) are represented as XML elements, including their names and values.
```xml
<?php declare(strict_types=1);
```
--------------------------------
### Install php-text-template as a project dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-text-template/README.md
This Composer command adds the phpunit/php-text-template library as a local, per-project dependency. It is suitable for production environments where the library is required for the application's runtime.
```PHP
composer require phpunit/php-text-template
```
--------------------------------
### Install phpunit/php-invoker as Development Dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-invoker/README.md
Use this Composer command to install `phpunit/php-invoker` as a development-time dependency. This is ideal when the library is only needed during development, such as for running test suites, and should not be included in production builds.
```Shell
composer require --dev phpunit/php-invoker
```
--------------------------------
### Create a Custom Deep Copy Wrapper Function
Source: https://github.com/shtse8/arbimath/blob/master/vendor/myclabs/deep-copy/README.md
Provides an example of how to wrap the DeepCopy library within your own custom `deep_copy` function. This pattern allows for centralized configuration, lazy initialization, and reuse across your application.
```php
namespace Acme;
use DeepCopy\DeepCopy;
function deep_copy($var)
{
static $copier = null;
if (null === $copier) {
$copier = new DeepCopy(true);
}
return $copier->copy($var);
}
```
--------------------------------
### Install sebastian/object-enumerator as a development dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/object-enumerator/README.md
Installs the sebastian/object-enumerator library as a development-only dependency using Composer. This is suitable for packages needed during testing, debugging, or other development tasks, and will not be included in production builds.
```bash
composer require --dev sebastian/object-enumerator
```
--------------------------------
### Example Modified AST Dump Output
Source: https://github.com/shtse8/arbimath/blob/master/vendor/nikic/php-parser/README.md
An example of the AST structure after it has been modified, specifically showing that the 'stmts' array for the function is now empty, reflecting the removal of its body.
```text
array(
0: Stmt_Function(
attrGroups: array(
)
byRef: false
name: Identifier(
name: test
)
params: array(
0: Param(
attrGroups: array(
)
type: null
byRef: false
variadic: false
var: Expr_Variable(
name: foo
)
default: null
)
)
returnType: null
stmts: array(
)
)
)
```
--------------------------------
### Example Output of PHP Manifest Reading and Serialization
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phar-io/manifest/README.md
Displays the console output after executing the PHP code snippet for reading and serializing a PHAR manifest. It includes the `var_dump` representation of the `Manifest` object and the resulting XML string.
```shell
object(PharIo\Manifest\Manifest)#14 (6) {
["name":"PharIo\Manifest\Manifest":private]=>
object(PharIo\Manifest\ApplicationName)#10 (1) {
["name":"PharIo\Manifest\ApplicationName":private]=>
string(12) "some/library"
}
["version":"PharIo\Manifest\Manifest":private]=>
object(PharIo\Version\Version)#12 (5) {
["originalVersionString":"PharIo\Version\Version":private]=>
string(5) "1.0.0"
["major":"PharIo\Version\Version":private]=>
object(PharIo\Version\VersionNumber)#13 (1) {
["value":"PharIo\Version\VersionNumber":private]=>
int(1)
}
["minor":"PharIo\Version\Version":private]=>
object(PharIo\Version\VersionNumber)#23 (1) {
["value":"PharIo\Version\VersionNumber":private]=>
int(0)
}
["patch":"PharIo\Version\Version":private]=>
object(PharIo\Version\VersionNumber)#22 (1) {
["value":"PharIo\Version\VersionNumber":private]=>
int(0)
}
["preReleaseSuffix":"PharIo\Version\Version":private]=>
NULL
}
["type":"PharIo\Manifest\Manifest":private]=>
object(PharIo\Manifest\Library)#6 (0) {
}
["copyrightInformation":"PharIo\Manifest\Manifest":private]=>
object(PharIo\Manifest\CopyrightInformation)#19 (2) {
["authors":"PharIo\Manifest\CopyrightInformation":private]=>
object(PharIo\Manifest\AuthorCollection)#9 (1) {
["authors":"PharIo\Manifest\AuthorCollection":private]=>
array(1) {
[0]=>
object(PharIo\Manifest\Author)#15 (2) {
["name":"PharIo\Manifest\Author":private]=>
string(13) "Reiner Zufall"
["email":"PharIo\Manifest\Author":private]=>
object(PharIo\Manifest\Email)#16 (1) {
["email":"PharIo\Manifest\Email":private]=>
string(16) "reiner@zufall.de"
}
}
}
}
["license":"PharIo\Manifest\CopyrightInformation":private]=>
object(PharIo\Manifest\License)#11 (2) {
["name":"PharIo\Manifest\License":private]=>
string(12) "BSD-3-Clause"
["url":"PharIo\Manifest\License":private]=>
object(PharIo\Manifest\Url)#18 (1) {
["url":"PharIo\Manifest\Url":private]=>
string(26) "https://domain.tld/LICENSE"
}
}
}
["requirements":"PharIo\Manifest\Manifest":private]=>
object(PharIo\Manifest\RequirementCollection)#17 (1) {
["requirements":"PharIo\Manifest\RequirementCollection":private]=>
array(1) {
[0]=>
object(PharIo\Manifest\PhpVersionRequirement)#20 (1) {
["versionConstraint":"PharIo\Version\PhpVersionRequirement":private]=>
object(PharIo\Version\SpecificMajorAndMinorVersionConstraint)#24 (3) {
["originalValue":"PharIo\Version\AbstractVersionConstraint":private]=>
string(3) "7.0"
["major":"PharIo\Version\SpecificMajorAndMinorVersionConstraint":private]=>
int(7)
["minor":"PharIo\Version\SpecificMajorAndMinorVersionConstraint":private]=>
int(0)
}
}
}
}
["bundledComponents":"PharIo\Manifest\Manifest":private]=>
object(PharIo\Manifest\BundledComponentCollection)#8 (1) {
["bundledComponents":"PharIo\Manifest\BundledComponentCollection":private]=>
array(0) {
}
}
}
```
--------------------------------
### Install sebastian/cli-parser as a production dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/cli-parser/README.md
This command adds the `sebastian/cli-parser` library as a local, per-project production dependency using Composer. It's intended for projects where the library is required for the application's runtime functionality.
```Shell
composer require sebastian/cli-parser
```
--------------------------------
### Install sebastian/complexity as Development Dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/complexity/README.md
Installs the sebastian/complexity library as a development-time dependency in your PHP project using Composer. This is typically used for tools like test suites that are not required for the application's runtime.
```Shell
composer require --dev sebastian/complexity
```
--------------------------------
### Install phpunit/php-invoker as Project Dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-invoker/README.md
This command adds the `phpunit/php-invoker` library as a local, per-project dependency to your PHP project using Composer. It's suitable for production environments where the library is required for the application's runtime.
```Shell
composer require phpunit/php-invoker
```
--------------------------------
### Install sebastian/code-unit-reverse-lookup as production dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/code-unit-reverse-lookup/README.md
This command adds the 'sebastian/code-unit-reverse-lookup' library as a local, per-project dependency to your project using Composer. It's intended for libraries required during your application's runtime.
```Shell
composer require sebastian/code-unit-reverse-lookup
```
--------------------------------
### Generate PHP Code Coverage Report
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-code-coverage/README.md
Demonstrates how to use phpunit/php-code-coverage to collect code coverage information and generate an HTML report. This snippet illustrates the typical workflow: initializing a Filter, creating a CodeCoverage instance with a Selector, starting and stopping coverage collection, and finally processing the results into an HTML report.
```php
includeFiles(
[
'/path/to/file.php',
'/path/to/another_file.php',
]
);
$coverage = new CodeCoverage(
(new Selector)->forLineCoverage($filter),
$filter
);
$coverage->start('');
// ...
$coverage->stop();
(new HtmlReport)->process($coverage, '/tmp/code-coverage-report');
```
--------------------------------
### Install sebastian/code-unit-reverse-lookup as development dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/code-unit-reverse-lookup/README.md
This command adds the 'sebastian/code-unit-reverse-lookup' library as a development-time dependency to your project using Composer. This is typically used for tools like test suites and will not be included in production builds.
```Shell
composer require --dev sebastian/code-unit-reverse-lookup
```
--------------------------------
### Install php-text-template as a development dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-text-template/README.md
This Composer command adds the phpunit/php-text-template library as a development-time dependency. It is typically used for tools or test suites that are only needed during the development phase and not in production.
```PHP
composer require --dev phpunit/php-text-template
```
--------------------------------
### Install sebastian/type as a development dependency using Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/type/README.md
Use this command to add the sebastian/type library as a development-time dependency. This is ideal for tools or libraries only needed during development, such as for running test suites.
```Shell
composer require --dev sebastian/type
```
--------------------------------
### Install phar.io/manifest with Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phar-io/manifest/README.md
Adds the phar.io/manifest library as a local, per-project dependency to your PHP project using Composer. This is the standard way to include the library for general use.
```shell
composer require phar.io/manifest
```
--------------------------------
### Install php-file-iterator as a production dependency using Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-file-iterator/README.md
This command adds the php-file-iterator library as a required dependency for your project. It's suitable for libraries or applications that need this functionality during runtime.
```Shell
composer require phpunit/php-file-iterator
```
--------------------------------
### Install sebastian/cli-parser as a development dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/cli-parser/README.md
This command adds the `sebastian/cli-parser` library as a development-time dependency using Composer. This is suitable for scenarios where the library is only needed during development, such as for running a project's test suite, and not in the production environment.
```Shell
composer require --dev sebastian/cli-parser
```
--------------------------------
### Install php-file-iterator as a development dependency using Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-file-iterator/README.md
This command adds the php-file-iterator library as a development-only dependency. It's typically used for tools required during testing or development, but not for the production runtime.
```Shell
composer require --dev phpunit/php-file-iterator
```
--------------------------------
### Install sebastian/lines-of-code as a production dependency using Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/lines-of-code/README.md
This command adds the sebastian/lines-of-code library as a required production dependency to your PHP project using Composer. It's suitable for libraries needed during runtime.
```Shell
composer require sebastian/lines-of-code
```
--------------------------------
### Install phar.io/manifest as Development Dependency
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phar-io/manifest/README.md
Adds the phar.io/manifest library as a development-time dependency using Composer. This is suitable if the library is only needed for development tasks, such as running tests, and not for the production runtime.
```shell
composer require --dev phar.io/manifest
```
--------------------------------
### Install sebastian/type as a production dependency using Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/type/README.md
This command adds the sebastian/type library as a local, per-project dependency to your PHP project using Composer. It's suitable for dependencies required in production environments.
```Shell
composer require sebastian/type
```
--------------------------------
### Traverse and Modify AST (PHP)
Source: https://github.com/shtse8/arbimath/blob/master/vendor/nikic/php-parser/README.md
Illustrates how to traverse an existing AST and perform modifications using NodeTraverser and a custom NodeVisitorAbstract. This example shows how to clear the statement bodies of all functions found in the AST.
```php
use PhpParser\Node;
use PhpParser\Node\Stmt\Function_;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitorAbstract;
$traverser = new NodeTraverser();
$traverser->addVisitor(new class extends NodeVisitorAbstract {
public function enterNode(Node $node) {
if ($node instanceof Function_) {
// Clean out the function body
$node->stmts = [];
}
}
});
$ast = $traverser->traverse($ast);
echo $dumper->dump($ast) . "\n";
```
--------------------------------
### Install sebastian/lines-of-code as a development dependency using Composer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/lines-of-code/README.md
This command adds the sebastian/lines-of-code library as a development-only dependency to your PHP project using Composer. It's typically used for tools like test suites or linters that are not needed in production.
```Shell
composer require --dev sebastian/lines-of-code
```
--------------------------------
### Perform High-Precision Calculations with ArbiMath PHP
Source: https://github.com/shtse8/arbimath/blob/master/README.md
This snippet demonstrates the basic usage of ArbiMath PHP. It shows how to instantiate ArbiNumber objects with high precision or large magnitudes, chain multiple arithmetic operations (multiplication, addition, exponentiation), and format the final result. An optional example for operator overloading with the PECL Operator extension is also included.
```PHP
mul($pi)->add($smallIncrement)->pow('3');
echo "Result: " . $result->toString() . "\n";
// Need formatting?
echo "Formatted: " . $result->format(10) . "\n"; // Format with separators and 10 decimal places
// With PECL Operator (Optional)
// $result = ($largeNumber * $pi + $smallIncrement) ** 3;
// echo $result;
?>
```
--------------------------------
### Measure code execution duration with php-timer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-timer/README.md
Demonstrates using `SebastianBergmann\Timer\Timer` to measure the execution time of a code block. It shows how to start and stop the timer, then retrieve the duration in various units like seconds, milliseconds, and nanoseconds.
```php
require __DIR__ . '/vendor/autoload.php';
use SebastianBergmann\Timer\Timer;
$timer = new Timer;
$timer->start();
foreach (\range(0, 100000) as $i) {
// ...
}
$duration = $timer->stop();
var_dump(get_class($duration));
var_dump($duration->asString());
var_dump($duration->asSeconds());
var_dump($duration->asMilliseconds());
var_dump($duration->asMicroseconds());
var_dump($duration->asNanoseconds());
```
--------------------------------
### Deprecated API Elements in SebastianBergmann\Diff Library
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/diff/ChangeLog.md
This snippet identifies methods that have been deprecated in the SebastianBergmann\Diff library, starting from version 5.1.0, indicating they will be removed in future major versions and should be replaced with their new counterparts.
```APIDOC
SebastianBergmann\Diff\Chunk:
getStart(): int
getStartRange(): int
getEnd(): int
getEndRange(): int
getLines(): array
SebastianBergmann\Diff\Diff:
getFrom(): int
getTo(): int
getChunks(): array
SebastianBergmann\Diff\Line:
getContent(): string
SebastianBergmann\Diff\Diff:
getType(): int
```
--------------------------------
### Exporting Simple PHP Data Types
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/exporter/README.md
Examples of using the Exporter class to visualize various simple PHP data types, including integers, floats, strings, booleans, special numeric values (NAN, INF), null, resources, and binary strings.
```PHP
export(46);
// 4.0
print $exporter->export(4.0);
// 'hello, world!'
print $exporter->export('hello, world!');
// false
print $exporter->export(false);
// NAN
print $exporter->export(acos(8));
// -INF
print $exporter->export(log(0));
// null
print $exporter->export(null);
// resource(13) of type (stream)
print $exporter->export(fopen('php://stderr', 'w'));
// Binary String: 0x000102030405
print $exporter->export(chr(0) . chr(1) . chr(2) . chr(3) . chr(4) . chr(5));
```
--------------------------------
### PHP DeepCopy: Using ShallowCopyFilter for Mock Objects
Source: https://github.com/shtse8/arbimath/blob/master/vendor/myclabs/deep-copy/README.md
This snippet demonstrates how to configure the `DeepCopy` library to use `ShallowCopyFilter` in conjunction with a `TypeMatcher` for `MockInterface` instances. This setup ensures that mock objects are shallow cloned instead of deep copied, preventing unintended modifications to their internal state during the copy process.
```php
use DeepCopy\DeepCopy;
use DeepCopy\TypeFilter\ShallowCopyFilter;
use DeepCopy\TypeMatcher\TypeMatcher;
use Mockery as m;
$this->deepCopy = new DeepCopy();
$this->deepCopy->addTypeFilter(
new ShallowCopyFilter,
new TypeMatcher(m\MockInterface::class)
);
$myServiceWithMocks = new MyService(m::mock(MyDependency1::class), m::mock(MyDependency2::class));
// All mocks will be just cloned, not deep copied
```
--------------------------------
### Basic Usage of SebastianBergmann\Version Class
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/version/README.md
Demonstrates how to instantiate the SebastianBergmann\Version class with a release number and path, then retrieve the version string using asString().
```php
asString());
```
--------------------------------
### Configure DeepCopy with Custom Options
Source: https://github.com/shtse8/arbimath/blob/master/vendor/myclabs/deep-copy/README.md
Illustrates how to instantiate the DeepCopy class with custom configuration options, such as enabling or disabling specific behaviors during the copy process. This allows for fine-grained control over the cloning mechanism.
```php
use DeepCopy\DeepCopy;
$copier = new DeepCopy(true);
$copy = $copier->copy($var);
```
--------------------------------
### API: Runtime Binary and Environment Information - Deprecations and Additions
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/environment/ChangeLog.md
Details on changes to methods for retrieving PHP binary paths and other runtime environment settings, including deprecations of older methods and the introduction of new functionalities.
```APIDOC
Method: Runtime::getBinary()
Status: Deprecated
Replacement: `escapeshellarg(PHP_BINARY)`
Method: Runtime::getRawBinary()
Status: Deprecated (previously added)
Replacement: `PHP_BINARY` constant
Method: Runtime::getCurrentSettings()
Status: Added, Fixed
Details: New method to retrieve current INI settings. Fixed issues with incorrect INI setting processing.
Method: Runtime::performsJustInTimeCompilation()
Status: Added
Details: Returns `true` if PHP 8's JIT is active, `false` otherwise.
Method: Runtime::getNameWithVersionAndCodeCoverageDriver()
Status: Added, Changed
Details: Implemented method to get runtime name with version and code coverage driver. Now prioritizes PCOV over Xdebug when both are loaded.
Method: Runtime::isHHVM()
Status: Removed
Details: Removed as HHVM is no longer supported.
Constant: PHP_OS_FAMILY
Status: Added (Equivalent)
Details: Implemented an equivalent for PHP versions older than 7.2.
```
--------------------------------
### API: PHP Version and JIT Compilation - Support and Fixes
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/environment/ChangeLog.md
Information regarding supported PHP versions for the component and fixes related to PHP's Just-in-Time (JIT) compiler behavior and OpCache settings.
```APIDOC
PHP Version Support:
- No longer supported on PHP 8.1, PHP 7.3, PHP 7.4, PHP 8.0, PHP 7.1, PHP 7.2.
- Now supported on PHP 8.
- PHP version constraint in `composer.json` changed from `^7.3 || ^8.0` to `>=7.3`.
JIT Compilation:
- Fixed: Just-in-Time compiler is disabled when `opcache.jit_buffer_size` is set to `0`.
- Fixed: The first `0` of `opcache.jit` only disables CPU-specific optimizations, not the Just-in-Time compiler itself.
```
--------------------------------
### API: Console Utility Methods - Changes and Fixes
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/environment/ChangeLog.md
Documentation for changes and fixes related to console utility methods, including color support detection and column count retrieval, ensuring better compatibility and reliability.
```APIDOC
Method: Console::hasColorSupport()
Status: Changed
Details: Synced with Symfony's `StreamOutput::hasColorSupport()` implementation. Improved Windows support for console capabilities.
Method: Console::getNumberOfColumnsInteractive()
Status: Fixed
Details: Resolved `TypeError` issues.
Class: Console
Status: Fixed
Details: Addressed regressions in the class behavior.
Command: stty
Status: Fixed
Details: Prevented execution of `stty` command when no tty is available.
```
--------------------------------
### API Reference for SebastianBergmann\Version Class
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/version/README.md
Details the constructor parameters and the public asString() method of the SebastianBergmann\Version class, explaining its behavior based on Git repository status and release format.
```APIDOC
SebastianBergmann\Version Class:
Constructor:
$release: string
Description: The version number of the latest release (X.Y.Z) or the name of the release series (X.Y) when no release has been made from that branch / for that release series yet.
$path: string
Description: The path to the directory (or a subdirectory thereof) where the sourcecode of the project can be found. Simply passing __DIR__ here usually suffices.
Methods:
asString(): string
Description: Returns the version string based on the Git repository status and the provided release format.
Behavior:
- If $path is not (part of) a Git repository and $release is in X.Y.Z format then $release is returned as-is.
- If $path is not (part of) a Git repository and $release is in X.Y format then $release is returned suffixed with '-dev'.
- If $path is (part of) a Git repository and $release is in X.Y.Z format then the output of 'git describe --tags' is returned as-is.
- If $path is (part of) a Git repository and $release is in X.Y format then a string is returned that begins with X.Y and ends with information from 'git describe --tags'.
```
--------------------------------
### Perform Deep Copy using deep_copy Helper Function
Source: https://github.com/shtse8/arbimath/blob/master/vendor/myclabs/deep-copy/README.md
Shows how to use the global `deep_copy` helper function for a quick and simple deep copy operation. This function provides a convenient shortcut for common deep copy scenarios.
```php
use function DeepCopy\deep_copy;
$copy = deep_copy($var);
```
--------------------------------
### DeepCopy Matcher API Documentation
Source: https://github.com/shtse8/arbimath/blob/master/vendor/myclabs/deep-copy/README.md
Documents the `DeepCopy\Matcher\Matcher` interface and its concrete implementations for defining rules to select properties for filtering during the deep copy process. Includes `PropertyNameMatcher`, `PropertyMatcher`, and `TypeMatcher` for flexible property selection.
```APIDOC
DeepCopy\Matcher\Matcher:
- Interface for matching object attributes.
DeepCopy\TypeMatcher\TypeMatcher:
- Applies on any element found in graph, including array elements.
PropertyNameMatcher:
__construct(propertyName: string)
propertyName: The name of the property to match.
Example:
$matcher = new PropertyNameMatcher('id');
// Will apply a filter to any property of any objects named "id"
PropertyMatcher:
__construct(className: string, propertyName: string)
className: The name of the class to match.
propertyName: The name of the property to match within the class.
Example:
$matcher = new PropertyMatcher('MyClass', 'id');
// Will apply a filter to the property "id" of any objects of the class "MyClass"
TypeMatcher:
__construct(type: string)
type: The type to match (class name or gettype() value).
Example:
$matcher = new TypeMatcher('Doctrine\Common\Collections\Collection');
// Will apply a filter to any object that is an instance of Doctrine\Common\Collections\Collection
```
--------------------------------
### Convert AST Back to PHP Code (PHP)
Source: https://github.com/shtse8/arbimath/blob/master/vendor/nikic/php-parser/README.md
Shows how to convert a modified Abstract Syntax Tree (AST) back into executable PHP code using the PrettyPrinter\Standard class, demonstrating the final step in a code transformation workflow.
```php
use PhpParser\PrettyPrinter;
$prettyPrinter = new PrettyPrinter\Standard;
echo $prettyPrinter->prettyPrintFile($ast);
```
--------------------------------
### Parse PHP Code to AST and Dump (PHP)
Source: https://github.com/shtse8/arbimath/blob/master/vendor/nikic/php-parser/README.md
Demonstrates how to parse a PHP code string into an Abstract Syntax Tree (AST) using ParserFactory and then dump the resulting AST in a human-readable format using NodeDumper. Includes basic error handling for parsing failures.
```php
createForNewestSupportedVersion();
try {
$ast = $parser->parse($code);
} catch (Error $error) {
echo "Parse error: {$error->getMessage()}\n";
return;
}
$dumper = new NodeDumper;
echo $dumper->dump($ast) . "\n";
```
--------------------------------
### Convert PHP Source Code to XML using Tokenizer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/theseer/tokenizer/README.md
Demonstrates parsing PHP source code into tokens and serializing them to XML. It uses TheSeer\Tokenizer\Tokenizer to parse a PHP file and TheSeer\Tokenizer\XMLSerializer to convert tokens to XML. The output is then echoed.
```php
$tokenizer = new TheSeer\Tokenizer\Tokenizer();
$tokens = $tokenizer->parse(file_get_contents(__DIR__ . '/src/XMLSerializer.php'));
$serializer = new TheSeer\Tokenizer\XMLSerializer();
$xml = $serializer->toXML($tokens);
echo $xml;
```
--------------------------------
### Generate a basic diff using SebastianBergmann\Diff\Differ
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/diff/README.md
Demonstrates how to use the `Differ` class to compare two strings and print their difference using the default output builder, which produces a unified diff format.
```php
diff('foo', 'bar');
```
--------------------------------
### Parse and Check Version Constraints in PHP
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phar-io/version/README.md
This snippet demonstrates parsing version constraints using `PharIo\Version\VersionConstraintParser` and checking compliance of discrete versions. It illustrates the behavior of both caret (`^`) and tilde (`~`) operators against specific version numbers.
```php
use PharIo\Version\Version;
use PharIo\Version\VersionConstraintParser;
$parser = new VersionConstraintParser();
$caret_constraint = $parser->parse( '^7.0' );
$caret_constraint->complies( new Version( '7.0.17' ) ); // true
$caret_constraint->complies( new Version( '7.1.0' ) ); // true
$caret_constraint->complies( new Version( '6.4.34' ) ); // false
$tilde_constraint = $parser->parse( '~1.1.0' );
$tilde_constraint->complies( new Version( '1.1.4' ) ); // true
$tilde_constraint->complies( new Version( '1.2.0' ) ); // false
```
--------------------------------
### Perform Deep Copy using DeepCopy Class
Source: https://github.com/shtse8/arbimath/blob/master/vendor/myclabs/deep-copy/README.md
Demonstrates the fundamental way to create a deep copy of an object using the DeepCopy class instance. This method allows for custom configurations and is the primary interface for the library.
```php
use DeepCopy\DeepCopy;
$copier = new DeepCopy();
$myCopy = $copier->copy($myObject);
```
--------------------------------
### KeepFilter: Preserve Property Value During Object Copy
Source: https://github.com/shtse8/arbimath/blob/master/vendor/myclabs/deep-copy/README.md
Illustrates the use of `KeepFilter` with `PropertyMatcher` to prevent a specific property (for example, an association like 'category') from being modified or deep-copied, ensuring it remains untouched in the copied object.
```php
use DeepCopy\DeepCopy;
use DeepCopy\Filter\KeepFilter;
use DeepCopy\Matcher\PropertyMatcher;
$copier = new DeepCopy();
$copier->addFilter(new KeepFilter(), new PropertyMatcher('MyClass', 'category'));
$copy = $copier->copy($object);
// $copy->category has not been touched
```
--------------------------------
### Create PharIo Manifest Programmatically in PHP
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phar-io/manifest/README.md
This PHP snippet demonstrates how to construct a PharIo manifest object, including details like application name, version, bundled components, and copyright information. It then serializes the manifest object into an XML string. This requires the `phar-io/manifest` library.
```php
$bundled = new \PharIo\Manifest\BundledComponentCollection();
$bundled->add(
new \PharIo\Manifest\BundledComponent('vendor/packageA', new \PharIo\Version\Version('1.2.3-dev')
)
);
$manifest = new PharIo\Manifest\Manifest(
new \PharIo\Manifest\ApplicationName('vendor/package'),
new \PharIo\Version\Version('1.0.0'),
new \PharIo\Manifest\Library(),
new \PharIo\Manifest\CopyrightInformation(
new \PharIo\Manifest\AuthorCollection(),
new \PharIo\Manifest\License(
'BSD-3-Clause',
new \PharIo\Manifest\Url('https://spdx.org/licenses/BSD-3-Clause.html')
)
),
new \PharIo\Manifest\RequirementCollection(),
$bundled
);
echo (new ManifestSerializer)->serializeToString($manifest);
```
```xml
```
--------------------------------
### Detect Standard Output Side-effect in PHP Code
Source: https://github.com/shtse8/arbimath/blob/master/vendor/staabm/side-effects-detector/README.md
This example demonstrates using `SideEffectsDetector` to identify `STANDARD_OUTPUT` side-effects, such as `echo` statements, within a given PHP code string. The detector returns an array of detected side-effect types, indicating the presence of output operations.
```php
use staabm\SideEffectsDetector\SideEffectsDetector;
$code = '=") or echo("skip because attributes are only available since PHP 8.0");';
$detector = new SideEffectsDetector();
// [SideEffect::STANDARD_OUTPUT]
var_dump($detector->getSideEffects($code));
```
--------------------------------
### Measure resource usage since PHP startup with php-timer
Source: https://github.com/shtse8/arbimath/blob/master/vendor/phpunit/php-timer/README.md
Shows how to report total resource consumption (time and memory) since the PHP script's startup. This method uses `SebastianBergmann\Timer\ResourceUsageFormatter` and relies on `$_SERVER['REQUEST_TIME_FLOAT']`, which can be unreliable.
```php
require __DIR__ . '/vendor/autoload.php';
use SebastianBergmann\Timer\ResourceUsageFormatter;
foreach (\range(0, 100000) as $i) {
// ...
}
print (new ResourceUsageFormatter)->resourceUsageSinceStartOfRequest();
```
--------------------------------
### Compare PHP DateTime objects using sebastian/comparator
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/comparator/README.md
Illustrates how to use `sebastian/comparator` to compare two `DateTime` objects for equality. It demonstrates obtaining a comparator from the `Factory` and catching `ComparisonFailure` exceptions.
```PHP
getComparatorFor($date1, $date2);
try {
$comparator->assertEquals($date1, $date2);
print "Dates match";
} catch (ComparisonFailure $failure) {
print "Dates don't match";
}
```
--------------------------------
### API: Miscellaneous Runtime Fixes and Removals
Source: https://github.com/shtse8/arbimath/blob/master/vendor/sebastian/environment/ChangeLog.md
Various fixes impacting runtime behavior, including stream handling, comment discarding, and removal of outdated components or functionalities.
```APIDOC
Function: stream_isatty(), fstat()
Status: Fixed
Details: Resolved wrong usage of `stream_isatty()` and `fstat()` without checking function availability.
Method: Runtime::discardsComments()
Status: Fixed, Removed Support
Details: Fixed method returning true too eagerly. Removed support for Zend Optimizer+.
Method: OperatingSystem::getFamily()
Status: Removed
Details: Removed because the component is no longer supported on PHP versions that do not have `PHP_OS_FAMILY`.
HHVM:
Status: Fixed
Details: Ensured PHP 7 mode of HHVM is correctly forced.
```