From 147f7a94895360f41e2777defae16b17db07c04e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 19 Aug 2019 12:16:25 +0200 Subject: [PATCH] update .gitattributes and .travis.yml (#6015) * update .gitattributes and ,travis.yml * move mkdir command * remove line * fix coding style * fix travis config --- .gitattributes | 17 +++++++----- .gitignore | 2 +- .travis.yml | 52 ++++++++++++++++++++++++++--------- autoload.php | 3 +- misc/file-test.php | 4 +-- misc/readme-report.php | 2 +- misc/sortTestFixtureFiles.php | 35 +++++++---------------- misc/statistics.php | 9 +++--- misc/test.php | 2 +- 9 files changed, 69 insertions(+), 57 deletions(-) diff --git a/.gitattributes b/.gitattributes index 38e8345f00..715069e97d 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,9 +1,12 @@ Tests/ export-ignore misc/ export-ignore -.coveralls.yml export-ignore -.travis.yml export-ignore -phpunit.xml.dist export-ignore -.gitignore export-ignore -.gitattributes export-ignore -.phpcs.xml export-ignore -.phpstan.neon export-ignore \ No newline at end of file +*.md text eol=lf +*.php text eol=lf +*.yml text eol=lf +.coveralls.yml text eol=lf export-ignore +.travis.yml text eol=lf export-ignore +phpunit.xml.dist text eol=lf export-ignore +.gitignore text eol=lf export-ignore +.gitattributes text eol=lf export-ignore +.phpcs.xml text eol=lf export-ignore +.phpstan.neon text eol=lf export-ignore diff --git a/.gitignore b/.gitignore index ddae7a316e..fbf9f5df16 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,4 @@ composer.lock composer.phar .buildpath .project -.settings \ No newline at end of file +.settings diff --git a/.travis.yml b/.travis.yml index 222358b1ec..e2f1b4037b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,26 +4,52 @@ php: - 7.1 - 7.2 - 7.3 - -dist: trusty + - 7.4snapshot + +dist: xenial sudo: false services: - memcached -before_script: - - (echo yes | pecl install -f memcache; true) +stages: + - style check + - static code analysis + - test + - test with coverage + +before_install: + - phpenv config-rm xdebug.ini || echo "xdebug not available" - (composer self-update; true) - - if [[ "$TRAVIS_PHP_VERSION" = 7.1 ]]; then composer require php-coveralls/php-coveralls ^2.1; fi - composer require doctrine/cache ~1.2 - - composer install -script: - - mkdir -p build/logs - - ./vendor/phpunit/phpunit/phpunit --coverage-clover build/logs/clover.xml - - if [[ "$TRAVIS_PHP_VERSION" = 7.1 ]]; then vendor/bin/phpstan analyse -c phpstan.neon . --no-interaction --no-progress; fi - - if [[ "$TRAVIS_PHP_VERSION" = 7.1 ]]; then vendor/bin/phpcs --standard=phpcs.xml .; fi +install: composer install + +script: vendor/bin/phpunit --no-coverage + +jobs: + allow_failures: + - php: 7.4snapshot + - php: nightly + include: + - php: nightly + install: travis_retry composer install --ignore-platform-reqs + + - stage: test with coverage + php: 7.1 + before_install: + - (composer self-update; true) + - composer require doctrine/cache ~1.2 + before_script: mkdir -p build/logs + script: vendor/bin/phpunit --coverage-clover build/logs/clover.xml --coverage-text + after_success: wget https://github.com/php-coveralls/php-coveralls/releases/download/v2.1.0/php-coveralls.phar && php -n php-coveralls.phar --verbose --coverage_clover=build/logs/clover.xml + + - stage: style check + php: 7.1 + script: php -n -d memory_limit=768M vendor/bin/phpcs --colors --standard=phpcs.xml . -after_success: - - if [[ "$TRAVIS_PHP_VERSION" = 7.1 ]]; then travis_retry php vendor/bin/php-coveralls -v; fi + - stage: static code analysis + os: linux + php: 7.1 + script: vendor/bin/phpstan analyse -c phpstan.neon --memory-limit=768M --no-interaction --no-progress . diff --git a/autoload.php b/autoload.php index 001b1af8c1..a874c1d52d 100644 --- a/autoload.php +++ b/autoload.php @@ -16,8 +16,7 @@ function dd_autoload($class) { if (strpos($class, 'DeviceDetector\\') !== false) { $namespace_map = array('DeviceDetector\\' => __DIR__ . '/'); - foreach ($namespace_map as $prefix => $dir) - { + foreach ($namespace_map as $prefix => $dir) { /* First swap out the namespace prefix with a directory... */ $path = str_replace($prefix, $dir, $class); /* replace the namespace separator with a directory separator... */ diff --git a/misc/file-test.php b/misc/file-test.php index 8fa2d65476..46e23199cf 100644 --- a/misc/file-test.php +++ b/misc/file-test.php @@ -98,11 +98,11 @@ function printReport($result, $format) if ($result['device']['model'] === '') { printReport($result, $reportMode); } - } else if ($showMode === DETECT_MODE_TYPE_DETECT) { + } elseif ($showMode === DETECT_MODE_TYPE_DETECT) { if ($result['device']['model'] !== '') { printReport($result, $reportMode); } - } else if ($showMode === DETECT_MODE_TYPE_ALL) { + } elseif ($showMode === DETECT_MODE_TYPE_ALL) { printReport($result, $reportMode); } } diff --git a/misc/readme-report.php b/misc/readme-report.php index dea4f708a4..f8c4c1fbf2 100644 --- a/misc/readme-report.php +++ b/misc/readme-report.php @@ -69,7 +69,7 @@ loadFile(__DIR__ . '/../regexes/bots.yml'); diff --git a/misc/sortTestFixtureFiles.php b/misc/sortTestFixtureFiles.php index 6810214894..a1e870b23b 100644 --- a/misc/sortTestFixtureFiles.php +++ b/misc/sortTestFixtureFiles.php @@ -9,16 +9,15 @@ $overwrite = !empty($argv[1]) && $argv[1] === '--f'; $data = array(); -foreach ($fixtureFiles AS $file) { +foreach ($fixtureFiles as $file) { - if (basename($file, '.yml') != 'unknown' && !in_array(preg_replace('/-[0-9]+$/', '', str_replace('_', ' ', basename($file, '.yml'))),array_keys( \DeviceDetector\Parser\Device\AbstractDeviceParser::getAvailableDeviceTypes() ))) { + if (basename($file, '.yml') != 'unknown' && !in_array(preg_replace('/-[0-9]+$/', '', str_replace('_', ' ', basename($file, '.yml'))), array_keys(\DeviceDetector\Parser\Device\AbstractDeviceParser::getAvailableDeviceTypes()))) { continue; } $fileFixtures = Spyc::YAMLLoad(file_get_contents($file)); - foreach( $fileFixtures AS $fixture) { - + foreach ($fileFixtures as $fixture) { if (isset($fixture['client']['short_name']) && $fixture['client']['short_name'] === true) { $fixture['client']['short_name'] = 'ON'; } @@ -32,30 +31,22 @@ } $data[$fixture['device']['type']][] = $fixture; - } } -foreach( $data AS $deviceType => $fixtures) { - +foreach ($data as $deviceType => $fixtures) { $fixtures = array_values(array_map("unserialize", array_unique(array_map("serialize", $fixtures)))); - usort($fixtures, function($a, $b) { - + usort($fixtures, function ($a, $b) { if (empty($b)) { return -1; } - if( @$a['device']['brand'] == @$b['device']['brand'] ) { - - if( strtolower(@$a['device']['model']) == strtolower(@$b['device']['model']) ) { - + if (@$a['device']['brand'] == @$b['device']['brand']) { + if (strtolower(@$a['device']['model']) == strtolower(@$b['device']['model'])) { if (@$a['os']['name'] == @$b['os']['name']) { - if (@$a['os']['version'] == @$b['os']['version']) { - if (@$a['client']['name'] == @$b['client']['name']) { - if (@$a['client']['version'] == @$b['client']['version']) { if ($a['user_agent'] == $b['user_agent']) { return 0; @@ -65,22 +56,18 @@ } return strtolower(@$a['client']['version']) < strtolower(@$b['client']['version']) ? -1 : 1; - } return strtolower(@$a['client']['name']) < strtolower(@$b['client']['name']) ? -1 : 1; - } return strtolower(@$a['os']['version']) < strtolower(@$b['os']['version']) ? -1 : 1; } return strtolower(@$a['os']['name']) < strtolower(@$b['os']['name']) ? -1 : 1; - } return strtolower(@$a['device']['model']) < strtolower(@$b['device']['model']) ? -1 : 1; - } return @$a['device']['brand'] < @$b['device']['brand'] ? -1 : 1; @@ -88,7 +75,7 @@ $chunks = array_chunk($fixtures, 500); - foreach($chunks AS $nr => $chunk) { + foreach ($chunks as $nr => $chunk) { $content = Spyc::YAMLDump($chunk, false, 0); $content = str_replace(": ON\n", ": 'ON'\n", $content); @@ -117,14 +104,13 @@ $botFixtures = Spyc::YAMLLoad(file_get_contents(__DIR__ . '/../Tests/fixtures/bots.yml')); -foreach( $botFixtures AS &$fixture) { +foreach ($botFixtures as &$fixture) { if ($overwrite) { $fixture = \DeviceDetector\DeviceDetector::getInfoFromUserAgent($fixture['user_agent']); } } -usort($botFixtures, function($a, $b) { - +usort($botFixtures, function ($a, $b) { if (empty($b)) { return -1; } @@ -143,4 +129,3 @@ file_put_contents(__DIR__ . '/../Tests/fixtures/bots.yml', Spyc::YAMLDump($botFixtures, false, 0)); echo "done.\n"; - diff --git a/misc/statistics.php b/misc/statistics.php index 347a0a5fd8..e84c842475 100644 --- a/misc/statistics.php +++ b/misc/statistics.php @@ -8,7 +8,7 @@ require_once(__DIR__.'/../vendor/autoload.php'); -if(count($argv) != 2) { +if (count($argv) != 2) { die("invalid arguments. Useage: php statistics.php filetoparse.txt"); } @@ -27,7 +27,6 @@ if ($handle) { while (($line = fgets($handle, 4096)) !== false) { - if (empty($line)) { continue; } @@ -53,7 +52,6 @@ } else { $unknownDeviceTypes++; } - } if (!feof($handle)) { echo "Error: unexpected fgets() fail\n"; @@ -63,7 +61,8 @@ $timeElapsed = microtime(true) - $startTime; -function getPercentage($cur, $max) { +function getPercentage($cur, $max) +{ return format(round($cur*100/$max), ' '); } @@ -110,4 +109,4 @@ function format($str, $length) format($deviceTypes[9], $parsedUAs), getPercentage($deviceTypes[9], $parsedUAs), format($deviceTypes[10], $parsedUAs), getPercentage($deviceTypes[10], $parsedUAs), format($unknownDeviceTypes, $parsedUAs), getPercentage($unknownDeviceTypes, $parsedUAs) -); \ No newline at end of file +); diff --git a/misc/test.php b/misc/test.php index 4483bf2478..e2baca5f22 100644 --- a/misc/test.php +++ b/misc/test.php @@ -39,4 +39,4 @@ echo Spyc::YAMLDump($result, 2, 0); -echo ""; \ No newline at end of file +echo "";