Skip to content

Commit

Permalink
update .gitattributes and .travis.yml (#6015)
Browse files Browse the repository at this point in the history
* update .gitattributes and ,travis.yml

* move mkdir command

* remove line

* fix coding style

* fix travis config
  • Loading branch information
mimmi20 authored and sgiehl committed Aug 19, 2019
1 parent f68014c commit 71f7ba4
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 57 deletions.
17 changes: 10 additions & 7 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
*.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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ composer.lock
composer.phar
.buildpath
.project
.settings
.settings
52 changes: 39 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 .
3 changes: 1 addition & 2 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -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... */
Expand Down
4 changes: 2 additions & 2 deletions misc/file-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
2 changes: 1 addition & 1 deletion misc/readme-report.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@

<?php

$bots = [];
$bots = array();
$ymlParser = new Spyc();

$parsedBots = $ymlParser->loadFile(__DIR__ . '/../regexes/bots.yml');
Expand Down
35 changes: 10 additions & 25 deletions misc/sortTestFixtureFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
Expand All @@ -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;
Expand All @@ -65,30 +56,26 @@
}

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;
});

$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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -143,4 +129,3 @@
file_put_contents(__DIR__ . '/../Tests/fixtures/bots.yml', Spyc::YAMLDump($botFixtures, false, 0));

echo "done.\n";

9 changes: 4 additions & 5 deletions misc/statistics.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}

Expand All @@ -27,7 +27,6 @@

if ($handle) {
while (($line = fgets($handle, 4096)) !== false) {

if (empty($line)) {
continue;
}
Expand All @@ -53,7 +52,6 @@
} else {
$unknownDeviceTypes++;
}

}
if (!feof($handle)) {
echo "Error: unexpected fgets() fail\n";
Expand All @@ -63,7 +61,8 @@

$timeElapsed = microtime(true) - $startTime;

function getPercentage($cur, $max) {
function getPercentage($cur, $max)
{
return format(round($cur*100/$max), ' ');
}

Expand Down Expand Up @@ -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)
);
);
2 changes: 1 addition & 1 deletion misc/test.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@

echo Spyc::YAMLDump($result, 2, 0);

echo "</pre>";
echo "</pre>";

0 comments on commit 71f7ba4

Please sign in to comment.