From 7fe89db0ae553b284802f43e106537924612c6cb Mon Sep 17 00:00:00 2001 From: Nenad Stojanovikj Date: Fri, 24 Jan 2020 14:15:22 +0100 Subject: [PATCH] Add php-cs-fixer (#50) * Add php-cs-fixer to dev requirements * Ignore php-cs-fixer cache file * Add style guide configuration file * Correct style of all PHP files * Add Makefile target for style fixing --- .gitignore | 3 +- .php_cs | 42 + Makefile | 2 + composer.json | 3 +- composer.lock | 811 +++++++++++++++++- examples/AlwaysOffTraceExample.php | 6 +- examples/AlwaysOnTraceExample.php | 28 +- src/Context/SpanContext.php | 4 +- src/Exporter/ZipkinExporter.php | 15 +- src/Trace/Event.php | 7 +- src/Trace/Sampler/AlwaysOffSampler.php | 3 + src/Trace/Sampler/AlwaysOnSampler.php | 5 +- src/Trace/Sampler/SamplerInterface.php | 5 +- src/Trace/Span.php | 16 +- .../SpanProcessor/SimpleSpanProcessor.php | 4 +- .../SpanProcessor/SpanProcessorInterface.php | 4 +- src/Trace/Status.php | 13 +- src/Trace/Tracer.php | 7 +- src/Trace/TracerFactory.php | 12 +- src/TransportInterface.php | 2 +- tests/integration/TracingTest.php | 16 +- tests/unit/Exporter/ZipkinExporterTest.php | 7 +- .../SpanProcessor/SimpleSpanProcessorTest.php | 4 +- tests/unit/Trace/TracerFactoryTest.php | 20 +- tests/unit/Trace/TracerTest.php | 4 +- .../Tracing/Sampler/AlwaysOffSamplerTest.php | 6 +- .../Tracing/Sampler/AlwaysOnSamplerTest.php | 2 + 27 files changed, 976 insertions(+), 75 deletions(-) create mode 100644 .php_cs diff --git a/.gitignore b/.gitignore index 78e2734a..b8bdaba8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ composer.phar vendor .idea/ coverage.clover -tests/coverage \ No newline at end of file +tests/coverage +.php_cs.cache diff --git a/.php_cs b/.php_cs new file mode 100644 index 00000000..45115c8d --- /dev/null +++ b/.php_cs @@ -0,0 +1,42 @@ +exclude('vendor') + ->exclude('var/cache') + ->in(__DIR__); + +return PhpCsFixer\Config::create() + ->setRules([ + 'concat_space' => ['spacing' => 'one'], + 'declare_equal_normalize' => ['space' => 'none'], + 'is_null' => true, + 'modernize_types_casting' => true, + 'ordered_imports' => true, + 'php_unit_construct' => true, + 'single_line_comment_style' => true, + 'yoda_style' => false, + '@PSR2' => true, + 'array_syntax' => ['syntax' => 'short'], + 'blank_line_after_opening_tag' => true, + 'blank_line_before_statement' => true, + 'cast_spaces' => true, + 'declare_strict_types' => true, + 'function_typehint_space' => true, + 'include' => true, + 'lowercase_cast' => true, + 'new_with_braces' => true, + 'no_extra_consecutive_blank_lines' => true, + 'no_leading_import_slash' => true, + 'no_short_echo_tag' => true, + 'no_unused_imports' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'phpdoc_order' => true, + 'phpdoc_scalar' => true, + 'phpdoc_types' => true, + 'short_scalar_cast' => true, + 'single_blank_line_before_namespace' => true, + 'single_quote' => true, + 'trailing_comma_in_multiline_array' => true, + ]) + ->setRiskyAllowed(true) + ->setFinder($finder); diff --git a/Makefile b/Makefile index 4a66b0af..f5ea288c 100644 --- a/Makefile +++ b/Makefile @@ -12,4 +12,6 @@ examples: FORCE $(DC_RUN_PHP) php ./examples/AlwaysOnTraceExample.php bash: $(DC_RUN_PHP) bash +style: + $(DC_RUN_PHP) php ./vendor/bin/php-cs-fixer fix FORCE: diff --git a/composer.json b/composer.json index 8d44ef71..9ea25b2f 100644 --- a/composer.json +++ b/composer.json @@ -30,6 +30,7 @@ "require-dev": { "phpunit/phpunit": "^7.5.16", "composer/xdebug-handler": "^1.3", - "phan/phan": "^2.4" + "phan/phan": "^2.4", + "friendsofphp/php-cs-fixer": "^2.16" } } diff --git a/composer.lock b/composer.lock index b5bb491e..b911d0fc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "2716ff13f408c12d4c10970cc416a6ac", + "content-hash": "ad5181452a8f29b7c5447e07c90c91d2", "packages": [], "packages-dev": [ { @@ -113,6 +113,74 @@ ], "time": "2019-11-06T16:40:04+00:00" }, + { + "name": "doctrine/annotations", + "version": "v1.8.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/annotations.git", + "reference": "904dca4eb10715b92569fbcd79e201d5c349b6bc" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/annotations/zipball/904dca4eb10715b92569fbcd79e201d5c349b6bc", + "reference": "904dca4eb10715b92569fbcd79e201d5c349b6bc", + "shasum": "" + }, + "require": { + "doctrine/lexer": "1.*", + "php": "^7.1" + }, + "require-dev": { + "doctrine/cache": "1.*", + "phpunit/phpunit": "^7.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.7.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Annotations\\": "lib/Doctrine/Common/Annotations" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Jonathan Wage", + "email": "jonwage@gmail.com" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "Docblock Annotations Parser", + "homepage": "http://www.doctrine-project.org", + "keywords": [ + "annotations", + "docblock", + "parser" + ], + "time": "2019-10-01T18:55:10+00:00" + }, { "name": "doctrine/instantiator", "version": "1.3.0", @@ -169,6 +237,68 @@ ], "time": "2019-10-21T16:45:58+00:00" }, + { + "name": "doctrine/lexer", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/doctrine/lexer.git", + "reference": "5242d66dbeb21a30dd8a3e66bf7a73b66e05e1f6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/doctrine/lexer/zipball/5242d66dbeb21a30dd8a3e66bf7a73b66e05e1f6", + "reference": "5242d66dbeb21a30dd8a3e66bf7a73b66e05e1f6", + "shasum": "" + }, + "require": { + "php": "^7.2" + }, + "require-dev": { + "doctrine/coding-standard": "^6.0", + "phpstan/phpstan": "^0.11.8", + "phpunit/phpunit": "^8.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Doctrine\\Common\\Lexer\\": "lib/Doctrine/Common/Lexer" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Guilherme Blanco", + "email": "guilhermeblanco@gmail.com" + }, + { + "name": "Roman Borschel", + "email": "roman@code-factory.org" + }, + { + "name": "Johannes Schmitt", + "email": "schmittjoh@gmail.com" + } + ], + "description": "PHP Doctrine Lexer parser library that can be used in Top-Down, Recursive Descent Parsers.", + "homepage": "https://www.doctrine-project.org/projects/lexer.html", + "keywords": [ + "annotations", + "docblock", + "lexer", + "parser", + "php" + ], + "time": "2019-10-30T14:39:59+00:00" + }, { "name": "felixfbecker/advanced-json-rpc", "version": "v3.0.4", @@ -210,6 +340,95 @@ "description": "A more advanced JSONRPC implementation", "time": "2019-09-12T22:41:08+00:00" }, + { + "name": "friendsofphp/php-cs-fixer", + "version": "v2.16.1", + "source": { + "type": "git", + "url": "https://github.com/FriendsOfPHP/PHP-CS-Fixer.git", + "reference": "c8afb599858876e95e8ebfcd97812d383fa23f02" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/zipball/c8afb599858876e95e8ebfcd97812d383fa23f02", + "reference": "c8afb599858876e95e8ebfcd97812d383fa23f02", + "shasum": "" + }, + "require": { + "composer/semver": "^1.4", + "composer/xdebug-handler": "^1.2", + "doctrine/annotations": "^1.2", + "ext-json": "*", + "ext-tokenizer": "*", + "php": "^5.6 || ^7.0", + "php-cs-fixer/diff": "^1.3", + "symfony/console": "^3.4.17 || ^4.1.6 || ^5.0", + "symfony/event-dispatcher": "^3.0 || ^4.0 || ^5.0", + "symfony/filesystem": "^3.0 || ^4.0 || ^5.0", + "symfony/finder": "^3.0 || ^4.0 || ^5.0", + "symfony/options-resolver": "^3.0 || ^4.0 || ^5.0", + "symfony/polyfill-php70": "^1.0", + "symfony/polyfill-php72": "^1.4", + "symfony/process": "^3.0 || ^4.0 || ^5.0", + "symfony/stopwatch": "^3.0 || ^4.0 || ^5.0" + }, + "require-dev": { + "johnkary/phpunit-speedtrap": "^1.1 || ^2.0 || ^3.0", + "justinrainbow/json-schema": "^5.0", + "keradus/cli-executor": "^1.2", + "mikey179/vfsstream": "^1.6", + "php-coveralls/php-coveralls": "^2.1", + "php-cs-fixer/accessible-object": "^1.0", + "php-cs-fixer/phpunit-constraint-isidenticalstring": "^1.1", + "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "^1.1", + "phpunit/phpunit": "^5.7.27 || ^6.5.14 || ^7.1", + "phpunitgoodpractices/traits": "^1.8", + "symfony/phpunit-bridge": "^4.3 || ^5.0", + "symfony/yaml": "^3.0 || ^4.0 || ^5.0" + }, + "suggest": { + "ext-mbstring": "For handling non-UTF8 characters in cache signature.", + "php-cs-fixer/phpunit-constraint-isidenticalstring": "For IsIdenticalString constraint.", + "php-cs-fixer/phpunit-constraint-xmlmatchesxsd": "For XmlMatchesXsd constraint.", + "symfony/polyfill-mbstring": "When enabling `ext-mbstring` is not possible." + }, + "bin": [ + "php-cs-fixer" + ], + "type": "application", + "autoload": { + "psr-4": { + "PhpCsFixer\\": "src/" + }, + "classmap": [ + "tests/Test/AbstractFixerTestCase.php", + "tests/Test/AbstractIntegrationCaseFactory.php", + "tests/Test/AbstractIntegrationTestCase.php", + "tests/Test/Assert/AssertTokensTrait.php", + "tests/Test/IntegrationCase.php", + "tests/Test/IntegrationCaseFactory.php", + "tests/Test/IntegrationCaseFactoryInterface.php", + "tests/Test/InternalIntegrationCaseFactory.php", + "tests/TestCase.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Dariusz RumiƄski", + "email": "dariusz.ruminski@gmail.com" + } + ], + "description": "A tool to automatically fix PHP code style", + "time": "2019-11-25T22:10:32+00:00" + }, { "name": "microsoft/tolerant-php-parser", "version": "v0.0.18", @@ -345,6 +564,51 @@ "description": "Map nested JSON structures onto PHP classes", "time": "2019-08-15T19:41:25+00:00" }, + { + "name": "paragonie/random_compat", + "version": "v9.99.99", + "source": { + "type": "git", + "url": "https://github.com/paragonie/random_compat.git", + "reference": "84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/paragonie/random_compat/zipball/84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95", + "reference": "84b4dfb120c6f9b4ff7b3685f9b8f1aa365a0c95", + "shasum": "" + }, + "require": { + "php": "^7" + }, + "require-dev": { + "phpunit/phpunit": "4.*|5.*", + "vimeo/psalm": "^1" + }, + "suggest": { + "ext-libsodium": "Provides a modern crypto API that can be used to generate random bytes." + }, + "type": "library", + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Paragon Initiative Enterprises", + "email": "security@paragonie.com", + "homepage": "https://paragonie.com" + } + ], + "description": "PHP 5.x polyfill for random_bytes() and random_int() from PHP 7", + "keywords": [ + "csprng", + "polyfill", + "pseudorandom", + "random" + ], + "time": "2018-07-02T15:55:56+00:00" + }, { "name": "phan/phan", "version": "2.4.5", @@ -520,6 +784,57 @@ "description": "Library for handling version information and constraints", "time": "2018-07-08T19:19:57+00:00" }, + { + "name": "php-cs-fixer/diff", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/PHP-CS-Fixer/diff.git", + "reference": "78bb099e9c16361126c86ce82ec4405ebab8e756" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/PHP-CS-Fixer/diff/zipball/78bb099e9c16361126c86ce82ec4405ebab8e756", + "reference": "78bb099e9c16361126c86ce82ec4405ebab8e756", + "shasum": "" + }, + "require": { + "php": "^5.6 || ^7.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7.23 || ^6.4.3", + "symfony/process": "^3.3" + }, + "type": "library", + "autoload": { + "classmap": [ + "src/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Kore Nordmann", + "email": "mail@kore-nordmann.de" + }, + { + "name": "Sebastian Bergmann", + "email": "sebastian@phpunit.de" + }, + { + "name": "SpacePossum" + } + ], + "description": "sebastian/diff v2 backport support for PHP5.6", + "homepage": "https://github.com/PHP-CS-Fixer", + "keywords": [ + "diff" + ], + "time": "2018-02-15T16:58:55+00:00" + }, { "name": "phpdocumentor/reflection-common", "version": "2.0.0", @@ -1867,6 +2182,287 @@ "homepage": "https://symfony.com", "time": "2019-12-17T10:32:23+00:00" }, + { + "name": "symfony/event-dispatcher", + "version": "v4.4.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher.git", + "reference": "9e3de195e5bc301704dd6915df55892f6dfc208b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9e3de195e5bc301704dd6915df55892f6dfc208b", + "reference": "9e3de195e5bc301704dd6915df55892f6dfc208b", + "shasum": "" + }, + "require": { + "php": "^7.1.3", + "symfony/event-dispatcher-contracts": "^1.1" + }, + "conflict": { + "symfony/dependency-injection": "<3.4" + }, + "provide": { + "psr/event-dispatcher-implementation": "1.0", + "symfony/event-dispatcher-implementation": "1.1" + }, + "require-dev": { + "psr/log": "~1.0", + "symfony/config": "^3.4|^4.0|^5.0", + "symfony/dependency-injection": "^3.4|^4.0|^5.0", + "symfony/expression-language": "^3.4|^4.0|^5.0", + "symfony/http-foundation": "^3.4|^4.0|^5.0", + "symfony/service-contracts": "^1.1|^2", + "symfony/stopwatch": "^3.4|^4.0|^5.0" + }, + "suggest": { + "symfony/dependency-injection": "", + "symfony/http-kernel": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.4-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\EventDispatcher\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony EventDispatcher Component", + "homepage": "https://symfony.com", + "time": "2020-01-10T21:54:01+00:00" + }, + { + "name": "symfony/event-dispatcher-contracts", + "version": "v1.1.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/event-dispatcher-contracts.git", + "reference": "c43ab685673fb6c8d84220c77897b1d6cdbe1d18" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/c43ab685673fb6c8d84220c77897b1d6cdbe1d18", + "reference": "c43ab685673fb6c8d84220c77897b1d6cdbe1d18", + "shasum": "" + }, + "require": { + "php": "^7.1.3" + }, + "suggest": { + "psr/event-dispatcher": "", + "symfony/event-dispatcher-implementation": "" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Contracts\\EventDispatcher\\": "" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Generic abstractions related to dispatching event", + "homepage": "https://symfony.com", + "keywords": [ + "abstractions", + "contracts", + "decoupling", + "interfaces", + "interoperability", + "standards" + ], + "time": "2019-09-17T09:54:03+00:00" + }, + { + "name": "symfony/filesystem", + "version": "v5.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/filesystem.git", + "reference": "3afadc0f57cd74f86379d073e694b0f2cda2a88c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/filesystem/zipball/3afadc0f57cd74f86379d073e694b0f2cda2a88c", + "reference": "3afadc0f57cd74f86379d073e694b0f2cda2a88c", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/polyfill-ctype": "~1.8" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Filesystem\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Filesystem Component", + "homepage": "https://symfony.com", + "time": "2020-01-21T08:40:24+00:00" + }, + { + "name": "symfony/finder", + "version": "v5.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/finder.git", + "reference": "4176e7cb846fe08f32518b7e0ed8462e2db8d9bb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/finder/zipball/4176e7cb846fe08f32518b7e0ed8462e2db8d9bb", + "reference": "4176e7cb846fe08f32518b7e0ed8462e2db8d9bb", + "shasum": "" + }, + "require": { + "php": "^7.2.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Finder\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Finder Component", + "homepage": "https://symfony.com", + "time": "2020-01-04T14:08:26+00:00" + }, + { + "name": "symfony/options-resolver", + "version": "v5.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/options-resolver.git", + "reference": "b1ab86ce52b0c0abe031367a173005a025e30e04" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/b1ab86ce52b0c0abe031367a173005a025e30e04", + "reference": "b1ab86ce52b0c0abe031367a173005a025e30e04", + "shasum": "" + }, + "require": { + "php": "^7.2.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\OptionsResolver\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony OptionsResolver Component", + "homepage": "https://symfony.com", + "keywords": [ + "config", + "configuration", + "options" + ], + "time": "2020-01-04T14:08:26+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.13.1", @@ -1984,6 +2580,120 @@ ], "time": "2019-11-27T14:18:11+00:00" }, + { + "name": "symfony/polyfill-php70", + "version": "v1.13.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php70.git", + "reference": "af23c7bb26a73b850840823662dda371484926c4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php70/zipball/af23c7bb26a73b850840823662dda371484926c4", + "reference": "af23c7bb26a73b850840823662dda371484926c4", + "shasum": "" + }, + "require": { + "paragonie/random_compat": "~1.0|~2.0|~9.99", + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.13-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php70\\": "" + }, + "files": [ + "bootstrap.php" + ], + "classmap": [ + "Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.0+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2019-11-27T13:56:44+00:00" + }, + { + "name": "symfony/polyfill-php72", + "version": "v1.13.1", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill-php72.git", + "reference": "66fea50f6cb37a35eea048d75a7d99a45b586038" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill-php72/zipball/66fea50f6cb37a35eea048d75a7d99a45b586038", + "reference": "66fea50f6cb37a35eea048d75a7d99a45b586038", + "shasum": "" + }, + "require": { + "php": ">=5.3.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.13-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Polyfill\\Php72\\": "" + }, + "files": [ + "bootstrap.php" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfill backporting some PHP 7.2+ features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compatibility", + "polyfill", + "portable", + "shim" + ], + "time": "2019-11-27T13:56:44+00:00" + }, { "name": "symfony/polyfill-php73", "version": "v1.13.1", @@ -2042,6 +2752,55 @@ ], "time": "2019-11-27T16:25:15+00:00" }, + { + "name": "symfony/process", + "version": "v5.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "f9ffd870f5ac01abec7b2b5e15f904ca9400ecd1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/f9ffd870f5ac01abec7b2b5e15f904ca9400ecd1", + "reference": "f9ffd870f5ac01abec7b2b5e15f904ca9400ecd1", + "shasum": "" + }, + "require": { + "php": "^7.2.5" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Process Component", + "homepage": "https://symfony.com", + "time": "2020-01-09T09:53:06+00:00" + }, { "name": "symfony/service-contracts", "version": "v1.1.8", @@ -2100,6 +2859,56 @@ ], "time": "2019-10-14T12:27:06+00:00" }, + { + "name": "symfony/stopwatch", + "version": "v5.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/stopwatch.git", + "reference": "5d9add8034135b9a5f7b101d1e42c797e7f053e4" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/stopwatch/zipball/5d9add8034135b9a5f7b101d1e42c797e7f053e4", + "reference": "5d9add8034135b9a5f7b101d1e42c797e7f053e4", + "shasum": "" + }, + "require": { + "php": "^7.2.5", + "symfony/service-contracts": "^1.0|^2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "5.0-dev" + } + }, + "autoload": { + "psr-4": { + "Symfony\\Component\\Stopwatch\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony Stopwatch Component", + "homepage": "https://symfony.com", + "time": "2020-01-04T14:08:26+00:00" + }, { "name": "theseer/tokenizer", "version": "1.1.3", diff --git a/examples/AlwaysOffTraceExample.php b/examples/AlwaysOffTraceExample.php index 2e9c5f34..d5098581 100644 --- a/examples/AlwaysOffTraceExample.php +++ b/examples/AlwaysOffTraceExample.php @@ -1,4 +1,6 @@ 'otuser', ]); $span->addEvent('generated_session', [ - 'id' => md5(microtime(true)) + 'id' => md5(microtime(true)), ]); $span->end(); // pass status as an optional argument print_r($span); // print the span as a resulting output } else { - echo "Sampling is not enabled"; + echo 'Sampling is not enabled'; } diff --git a/examples/AlwaysOnTraceExample.php b/examples/AlwaysOnTraceExample.php index 0e39d8ca..3ce0500d 100644 --- a/examples/AlwaysOnTraceExample.php +++ b/examples/AlwaysOnTraceExample.php @@ -1,10 +1,12 @@ getTracer('io.opentelemetry.contrib.php'); -for ($i = 0; $i < 5; $i++) { - // start a span, register some events - $span = $tracer->createSpan('session.generate.span'. $i); - $tracer->setActiveSpan($span); + for ($i = 0; $i < 5; $i++) { + // start a span, register some events + $span = $tracer->createSpan('session.generate.span' . $i); + $tracer->setActiveSpan($span); - $span->setAttributes(['remote_ip' => '1.2.3.4']); - $span->setAttribute('country', 'USA'); + $span->setAttributes(['remote_ip' => '1.2.3.4']); + $span->setAttribute('country', 'USA'); - $span->addEvent('found_login'. $i, [ + $span->addEvent('found_login' . $i, [ 'id' => $i, 'username' => 'otuser' . $i, ]); - $span->addEvent('generated_session', [ - 'id' => md5(microtime(true)) + $span->addEvent('generated_session', [ + 'id' => md5(microtime(true)), ]); - $tracer->endActiveSpan(); -} + $tracer->endActiveSpan(); + } } else { - echo "Sampling is not enabled"; + echo 'Sampling is not enabled'; } diff --git a/src/Context/SpanContext.php b/src/Context/SpanContext.php index 1597c683..d02fdf65 100644 --- a/src/Context/SpanContext.php +++ b/src/Context/SpanContext.php @@ -51,13 +51,13 @@ class SpanContext return $this->spanId; } - /* TODO : Finish this function */ + // TODO : Finish this function public function IsValid() : bool { return false; } - /* TODO : Finish this function */ + // TODO : Finish this function public function IsRemote() : bool { return false; diff --git a/src/Exporter/ZipkinExporter.php b/src/Exporter/ZipkinExporter.php index 610cb7dd..31d30ff3 100644 --- a/src/Exporter/ZipkinExporter.php +++ b/src/Exporter/ZipkinExporter.php @@ -56,13 +56,11 @@ class ZipkinExporter implements ExporterInterface 'http' => [ 'method' => 'POST', 'header' => 'Content-Type: application/json', - 'content' => $json - ] + 'content' => $json, + ], ]; $context = stream_context_create($contextOptions); file_get_contents($this->getEndpointUrl(), false, $context); - - } catch (Exception $e) { return ExporterInterface::FAILED_RETRYABLE; } @@ -86,11 +84,11 @@ class ZipkinExporter implements ExporterInterface : null, 'localEndpoint' => [ 'serviceName' => $this->name, - 'port' => $this->getEndpoint()['port'] ?? 0 + 'port' => $this->getEndpoint()['port'] ?? 0, ], 'name' => $span->getName(), - 'timestamp' => (integer) round($span->getStart()*1000000), - 'duration' => (integer) round($span->getEnd()*1000000) - round($span->getStart()*1000000), + 'timestamp' => (int) round($span->getStart()*1000000), + 'duration' => (int) round($span->getEnd()*1000000) - round($span->getStart()*1000000), ]; foreach ($span->getAttributes() as $k => $v) { @@ -143,13 +141,14 @@ class ZipkinExporter implements ExporterInterface } $this->endpoint = $endpoint; + return $this; } protected function getEndpointUrl(): string { return sprintf( - "%s://%s:%s%s", + '%s://%s:%s%s', $this->endpoint['scheme'], $this->endpoint['host'], $this->endpoint['port'], diff --git a/src/Trace/Event.php b/src/Trace/Event.php index b87a0a56..4eee90fa 100644 --- a/src/Trace/Event.php +++ b/src/Trace/Event.php @@ -12,7 +12,7 @@ class Event public function __construct(string $name, iterable $attributes = [], $timestamp = null) { - if (is_null($timestamp)) { + if (null === $timestamp) { $timestamp = microtime(true); } $this->name = $name; @@ -25,12 +25,14 @@ class Event if (!array_key_exists($key, $this->attributes)) { return null; } + return $this->attributes[$key]; } public function setAttribute(string $key, $value) : self { $this->attributes[$key] = $value; + return $this; } @@ -45,6 +47,7 @@ class Event foreach ($attributes as $k => $v) { $this->setAttribute($k, $v); } + return $this; } @@ -57,4 +60,4 @@ class Event { return $this->timestamp; } -} \ No newline at end of file +} diff --git a/src/Trace/Sampler/AlwaysOffSampler.php b/src/Trace/Sampler/AlwaysOffSampler.php index fa77b1c9..6feb7946 100644 --- a/src/Trace/Sampler/AlwaysOffSampler.php +++ b/src/Trace/Sampler/AlwaysOffSampler.php @@ -1,4 +1,7 @@ end = $timestamp ?? microtime(true); $this->statusCode = $statusCode; $this->statusDescription = null; + return $this; } @@ -93,7 +93,7 @@ class Span // -> This had an update this past month: https://github.com/open-telemetry/opentelemetry-specification/blob/master/specification/api-tracing.md#isrecording public function isRecording(): bool { - return is_null($this->end); + return null === $this->end; } public function getDuration(): ?float @@ -101,6 +101,7 @@ class Span if (!$this->end) { return null; } + return $this->end - $this->start; } @@ -112,6 +113,7 @@ class Span public function updateName(string $name): self { $this->name = $name; + return $this; } @@ -120,6 +122,7 @@ class Span if (!array_key_exists($key, $this->attributes)) { return null; } + return $this->attributes[$key]; } @@ -130,6 +133,7 @@ class Span } $this->attributes[$key] = $value; + return $this; } @@ -146,6 +150,7 @@ class Span foreach ($attributes as $k => $v) { $this->setAttribute($k, $v); } + return $this; } @@ -157,6 +162,7 @@ class Span $event = new Event($name, $attributes, $timestamp); // todo: check that these are all Attributes -> What do we want to check about these? Just a 'property_exist' check on this? $this->events[] = $event; + return $event; } @@ -178,7 +184,7 @@ class Span private function throwIfNotRecording() { if (!$this->isRecording()) { - throw new Exception("Span is readonly"); + throw new Exception('Span is readonly'); } } -} \ No newline at end of file +} diff --git a/src/Trace/SpanProcessor/SimpleSpanProcessor.php b/src/Trace/SpanProcessor/SimpleSpanProcessor.php index d489a8f3..e0069eff 100644 --- a/src/Trace/SpanProcessor/SimpleSpanProcessor.php +++ b/src/Trace/SpanProcessor/SimpleSpanProcessor.php @@ -1,5 +1,7 @@ exporter->export([$span]); } -} \ No newline at end of file +} diff --git a/src/Trace/SpanProcessor/SpanProcessorInterface.php b/src/Trace/SpanProcessor/SpanProcessorInterface.php index b7f013f9..861656ca 100644 --- a/src/Trace/SpanProcessor/SpanProcessorInterface.php +++ b/src/Trace/SpanProcessor/SpanProcessorInterface.php @@ -1,5 +1,7 @@ description = $description; } } - public static function new(int $code, string $description = null) { + public static function new(int $code, string $description = null) + { if ($code === self::OK && ($description === null || $description == self::DESCRIPTION[self::OK])) { return self::$ok; } + return new Status($code, $description); } - public static function initOk() { + public static function initOk() + { if (!self::$ok) { self::$ok = new Status(self::OK); } @@ -88,4 +91,4 @@ class Status } } -Status::initOk(); \ No newline at end of file +Status::initOk(); diff --git a/src/Trace/Tracer.php b/src/Trace/Tracer.php index 922dd1f6..f5f83687 100644 --- a/src/Trace/Tracer.php +++ b/src/Trace/Tracer.php @@ -21,7 +21,7 @@ class Tracer * Tracer constructor. * * @param SpanProcessorInterface[] $spanProcessors - * @param SpanContext|NULL $context + * @param SpanContext|null $context */ public function __construct(iterable $spanProcessors = [], SpanContext $context = null) { @@ -35,12 +35,14 @@ class Tracer while (count($this->tail) && $this->active->getEnd()) { $this->active = array_pop($this->tail); } + return $this->active; } public function setActiveSpan(Span $span): Span { $this->tail[] = $this->active; + return $this->active = $span; } @@ -93,7 +95,7 @@ class Tracer int $statusCode = Status::OK, ?string $statusDescription = null, float $timestamp = null - ){ + ) { if ($this->getActiveSpan()->isRecording()) { foreach ($this->spanProcessors as $spanProcessor) { $spanProcessor->onEnd($this->getActiveSpan()); @@ -111,6 +113,7 @@ class Tracer } $span = new Span($name, $context, $parent); $this->spans[] = $span; + return $span; } } diff --git a/src/Trace/TracerFactory.php b/src/Trace/TracerFactory.php index 013c6c80..ddd1bdab 100644 --- a/src/Trace/TracerFactory.php +++ b/src/Trace/TracerFactory.php @@ -1,5 +1,7 @@ tracers[$name] instanceof Tracer) { return $this->tracers[$name]; } $spanContext = SpanContext::generate(); + return $this->tracers[$name] = new Tracer($this->spanProcessors, $spanContext); } -} \ No newline at end of file +} diff --git a/src/TransportInterface.php b/src/TransportInterface.php index 6755bc41..7c938c40 100644 --- a/src/TransportInterface.php +++ b/src/TransportInterface.php @@ -7,4 +7,4 @@ namespace OpenTelemetry; interface TransportInterface { public function write(array $data) : bool; -} \ No newline at end of file +} diff --git a/tests/integration/TracingTest.php b/tests/integration/TracingTest.php index 81333c7a..8939138e 100644 --- a/tests/integration/TracingTest.php +++ b/tests/integration/TracingTest.php @@ -4,9 +4,9 @@ declare(strict_types=1); namespace OpenTelemetry\Tests\Integration; +use OpenTelemetry\Context\SpanContext; use OpenTelemetry\Exporter\BasisExporter; use OpenTelemetry\Exporter\ZipkinExporter; -use OpenTelemetry\Context\SpanContext; use OpenTelemetry\Trace\Status; use OpenTelemetry\Trace\Tracer; use PHPUnit\Framework\TestCase; @@ -42,7 +42,7 @@ class TracingTest extends TestCase public function testSpanNameUpdate() { - $database = (new Tracer)->createSpan('database'); + $database = (new Tracer())->createSpan('database'); $this->assertSame($database->getName(), 'database'); $database->updateName('tarantool'); $this->assertSame($database->getName(), 'tarantool'); @@ -152,17 +152,17 @@ class TracingTest extends TestCase $span->setAttribute('b', 4); $this->assertSame(array_keys($span->getAttributes()), ['b', 'a']); - $this->expectExceptionMessage("Span is readonly"); + $this->expectExceptionMessage('Span is readonly'); $span->end(); $span->setAttribute('b', 5); } public function testEventRegistration() { - $span = (new Tracer)->createSpan('database'); + $span = (new Tracer())->createSpan('database'); $event = $span->addEvent('select', [ 'space' => 'guard.session', - 'id' => 67235 + 'id' => 67235, ]); $this->assertSame($event->getName(), 'select'); $this->assertSame($event->getAttributes(), [ @@ -181,7 +181,7 @@ class TracingTest extends TestCase $this->assertCount(2, $span->getEvents()); - $this->expectExceptionMessage("Span is readonly"); + $this->expectExceptionMessage('Span is readonly'); $span->end(); $span->addEvent('update'); } @@ -197,7 +197,7 @@ class TracingTest extends TestCase public function testParentSpanContext() { - $tracer = new Tracer; + $tracer = new Tracer(); $global = $tracer->getActiveSpan(); $request = $tracer->createSpan('request'); $this->assertSame($request->getParentContext()->getSpanId(), $global->getContext()->getSpanId()); @@ -285,4 +285,4 @@ class TracingTest extends TestCase $this->assertSame($annotation['value'], $event->getName()); $this->assertSame($annotation['timestamp'], 1000000 * $event->getTimestamp()); } -} \ No newline at end of file +} diff --git a/tests/unit/Exporter/ZipkinExporterTest.php b/tests/unit/Exporter/ZipkinExporterTest.php index a9a782b3..f2f95ee9 100644 --- a/tests/unit/Exporter/ZipkinExporterTest.php +++ b/tests/unit/Exporter/ZipkinExporterTest.php @@ -1,5 +1,7 @@ assertArrayHasKey('scheme', $exporter->getEndpoint()); $this->assertArrayHasKey('host', $exporter->getEndpoint()); $this->assertArrayHasKey('port', $exporter->getEndpoint()); $this->assertArrayHasKey('path', $exporter->getEndpoint()); - } /** @@ -45,4 +46,4 @@ class ZipkinExporterTest extends TestCase 'invalid host' => ['scheme:///end:1234/path'], ]; } -} \ No newline at end of file +} diff --git a/tests/unit/Trace/SpanProcessor/SimpleSpanProcessorTest.php b/tests/unit/Trace/SpanProcessor/SimpleSpanProcessorTest.php index a843b530..56f6eefe 100644 --- a/tests/unit/Trace/SpanProcessor/SimpleSpanProcessorTest.php +++ b/tests/unit/Trace/SpanProcessor/SimpleSpanProcessorTest.php @@ -1,5 +1,7 @@ createMock(SpanProcessorInterface::class), $this->createMock(SpanProcessorInterface::class), - $this->createMock(SpanProcessorInterface::class) ]); - $this->assertInstanceOf(TracerFactory::class, $factory); + $this->assertInstanceOf(TracerFactory::class, $factory); } /** @@ -78,17 +80,17 @@ class TracerFactoryTest extends TestCase { return [ 'array of numbers' => [ - 'spanProcessors' => [1, -1, 0.1, -0.1, 0] + 'spanProcessors' => [1, -1, 0.1, -0.1, 0], ], 'array of strings' => [ - 'spanProcessors' => ['aaa', 'bbb', ''] + 'spanProcessors' => ['aaa', 'bbb', ''], ], 'array of standardObjects' => [ - 'spanProcessors' => [new StdClass(), new StdClass()] + 'spanProcessors' => [new StdClass(), new StdClass()], ], 'array of boolean' => [ - 'spanProcessors' => [true, false, null] - ] + 'spanProcessors' => [true, false, null], + ], ]; } -} \ No newline at end of file +} diff --git a/tests/unit/Trace/TracerTest.php b/tests/unit/Trace/TracerTest.php index f2644cd0..c59ff0bc 100644 --- a/tests/unit/Trace/TracerTest.php +++ b/tests/unit/Trace/TracerTest.php @@ -1,5 +1,7 @@ createSpan('test.span'); $tracer->endActiveSpan(); } -} \ No newline at end of file +} diff --git a/tests/unit/Tracing/Sampler/AlwaysOffSamplerTest.php b/tests/unit/Tracing/Sampler/AlwaysOffSamplerTest.php index dd8ba827..edf0e08a 100644 --- a/tests/unit/Tracing/Sampler/AlwaysOffSamplerTest.php +++ b/tests/unit/Tracing/Sampler/AlwaysOffSamplerTest.php @@ -1,8 +1,12 @@ assertFalse($sampler->shouldSample()); } -} +} diff --git a/tests/unit/Tracing/Sampler/AlwaysOnSamplerTest.php b/tests/unit/Tracing/Sampler/AlwaysOnSamplerTest.php index e9f586a9..5d06b64c 100644 --- a/tests/unit/Tracing/Sampler/AlwaysOnSamplerTest.php +++ b/tests/unit/Tracing/Sampler/AlwaysOnSamplerTest.php @@ -1,5 +1,7 @@