Skip to content

Commit 147f7a9

Browse files
mimmi20sgiehl
authored andcommitted
update .gitattributes and .travis.yml (#6015)
* update .gitattributes and ,travis.yml * move mkdir command * remove line * fix coding style * fix travis config
1 parent c63103f commit 147f7a9

File tree

9 files changed

+69
-57
lines changed

9 files changed

+69
-57
lines changed

.gitattributes

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
Tests/ export-ignore
22
misc/ export-ignore
3-
.coveralls.yml export-ignore
4-
.travis.yml export-ignore
5-
phpunit.xml.dist export-ignore
6-
.gitignore export-ignore
7-
.gitattributes export-ignore
8-
.phpcs.xml export-ignore
9-
.phpstan.neon export-ignore
3+
*.md text eol=lf
4+
*.php text eol=lf
5+
*.yml text eol=lf
6+
.coveralls.yml text eol=lf export-ignore
7+
.travis.yml text eol=lf export-ignore
8+
phpunit.xml.dist text eol=lf export-ignore
9+
.gitignore text eol=lf export-ignore
10+
.gitattributes text eol=lf export-ignore
11+
.phpcs.xml text eol=lf export-ignore
12+
.phpstan.neon text eol=lf export-ignore

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ composer.lock
44
composer.phar
55
.buildpath
66
.project
7-
.settings
7+
.settings

.travis.yml

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,52 @@ php:
44
- 7.1
55
- 7.2
66
- 7.3
7-
8-
dist: trusty
7+
- 7.4snapshot
8+
9+
dist: xenial
910

1011
sudo: false
1112

1213
services:
1314
- memcached
1415

15-
before_script:
16-
- (echo yes | pecl install -f memcache; true)
16+
stages:
17+
- style check
18+
- static code analysis
19+
- test
20+
- test with coverage
21+
22+
before_install:
23+
- phpenv config-rm xdebug.ini || echo "xdebug not available"
1724
- (composer self-update; true)
18-
- if [[ "$TRAVIS_PHP_VERSION" = 7.1 ]]; then composer require php-coveralls/php-coveralls ^2.1; fi
1925
- composer require doctrine/cache ~1.2
20-
- composer install
2126

22-
script:
23-
- mkdir -p build/logs
24-
- ./vendor/phpunit/phpunit/phpunit --coverage-clover build/logs/clover.xml
25-
- if [[ "$TRAVIS_PHP_VERSION" = 7.1 ]]; then vendor/bin/phpstan analyse -c phpstan.neon . --no-interaction --no-progress; fi
26-
- if [[ "$TRAVIS_PHP_VERSION" = 7.1 ]]; then vendor/bin/phpcs --standard=phpcs.xml .; fi
27+
install: composer install
28+
29+
script: vendor/bin/phpunit --no-coverage
30+
31+
jobs:
32+
allow_failures:
33+
- php: 7.4snapshot
34+
- php: nightly
35+
include:
36+
- php: nightly
37+
install: travis_retry composer install --ignore-platform-reqs
38+
39+
- stage: test with coverage
40+
php: 7.1
41+
before_install:
42+
- (composer self-update; true)
43+
- composer require doctrine/cache ~1.2
44+
before_script: mkdir -p build/logs
45+
script: vendor/bin/phpunit --coverage-clover build/logs/clover.xml --coverage-text
46+
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
47+
48+
- stage: style check
49+
php: 7.1
50+
script: php -n -d memory_limit=768M vendor/bin/phpcs --colors --standard=phpcs.xml .
2751

28-
after_success:
29-
- if [[ "$TRAVIS_PHP_VERSION" = 7.1 ]]; then travis_retry php vendor/bin/php-coveralls -v; fi
52+
- stage: static code analysis
53+
os: linux
54+
php: 7.1
55+
script: vendor/bin/phpstan analyse -c phpstan.neon --memory-limit=768M --no-interaction --no-progress .

autoload.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@ function dd_autoload($class)
1616
{
1717
if (strpos($class, 'DeviceDetector\\') !== false) {
1818
$namespace_map = array('DeviceDetector\\' => __DIR__ . '/');
19-
foreach ($namespace_map as $prefix => $dir)
20-
{
19+
foreach ($namespace_map as $prefix => $dir) {
2120
/* First swap out the namespace prefix with a directory... */
2221
$path = str_replace($prefix, $dir, $class);
2322
/* replace the namespace separator with a directory separator... */

misc/file-test.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,11 @@ function printReport($result, $format)
9898
if ($result['device']['model'] === '') {
9999
printReport($result, $reportMode);
100100
}
101-
} else if ($showMode === DETECT_MODE_TYPE_DETECT) {
101+
} elseif ($showMode === DETECT_MODE_TYPE_DETECT) {
102102
if ($result['device']['model'] !== '') {
103103
printReport($result, $reportMode);
104104
}
105-
} else if ($showMode === DETECT_MODE_TYPE_ALL) {
105+
} elseif ($showMode === DETECT_MODE_TYPE_ALL) {
106106
printReport($result, $reportMode);
107107
}
108108
}

misc/readme-report.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
<?php
7171

72-
$bots = [];
72+
$bots = array();
7373
$ymlParser = new Spyc();
7474

7575
$parsedBots = $ymlParser->loadFile(__DIR__ . '/../regexes/bots.yml');

misc/sortTestFixtureFiles.php

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,15 @@
99
$overwrite = !empty($argv[1]) && $argv[1] === '--f';
1010
$data = array();
1111

12-
foreach ($fixtureFiles AS $file) {
12+
foreach ($fixtureFiles as $file) {
1313

14-
if (basename($file, '.yml') != 'unknown' && !in_array(preg_replace('/-[0-9]+$/', '', str_replace('_', ' ', basename($file, '.yml'))),array_keys( \DeviceDetector\Parser\Device\AbstractDeviceParser::getAvailableDeviceTypes() ))) {
14+
if (basename($file, '.yml') != 'unknown' && !in_array(preg_replace('/-[0-9]+$/', '', str_replace('_', ' ', basename($file, '.yml'))), array_keys(\DeviceDetector\Parser\Device\AbstractDeviceParser::getAvailableDeviceTypes()))) {
1515
continue;
1616
}
1717

1818
$fileFixtures = Spyc::YAMLLoad(file_get_contents($file));
1919

20-
foreach( $fileFixtures AS $fixture) {
21-
20+
foreach ($fileFixtures as $fixture) {
2221
if (isset($fixture['client']['short_name']) && $fixture['client']['short_name'] === true) {
2322
$fixture['client']['short_name'] = 'ON';
2423
}
@@ -32,30 +31,22 @@
3231
}
3332

3433
$data[$fixture['device']['type']][] = $fixture;
35-
3634
}
3735
}
3836

39-
foreach( $data AS $deviceType => $fixtures) {
40-
37+
foreach ($data as $deviceType => $fixtures) {
4138
$fixtures = array_values(array_map("unserialize", array_unique(array_map("serialize", $fixtures))));
4239

43-
usort($fixtures, function($a, $b) {
44-
40+
usort($fixtures, function ($a, $b) {
4541
if (empty($b)) {
4642
return -1;
4743
}
4844

49-
if( @$a['device']['brand'] == @$b['device']['brand'] ) {
50-
51-
if( strtolower(@$a['device']['model']) == strtolower(@$b['device']['model']) ) {
52-
45+
if (@$a['device']['brand'] == @$b['device']['brand']) {
46+
if (strtolower(@$a['device']['model']) == strtolower(@$b['device']['model'])) {
5347
if (@$a['os']['name'] == @$b['os']['name']) {
54-
5548
if (@$a['os']['version'] == @$b['os']['version']) {
56-
5749
if (@$a['client']['name'] == @$b['client']['name']) {
58-
5950
if (@$a['client']['version'] == @$b['client']['version']) {
6051
if ($a['user_agent'] == $b['user_agent']) {
6152
return 0;
@@ -65,30 +56,26 @@
6556
}
6657

6758
return strtolower(@$a['client']['version']) < strtolower(@$b['client']['version']) ? -1 : 1;
68-
6959
}
7060

7161
return strtolower(@$a['client']['name']) < strtolower(@$b['client']['name']) ? -1 : 1;
72-
7362
}
7463

7564
return strtolower(@$a['os']['version']) < strtolower(@$b['os']['version']) ? -1 : 1;
7665
}
7766

7867
return strtolower(@$a['os']['name']) < strtolower(@$b['os']['name']) ? -1 : 1;
79-
8068
}
8169

8270
return strtolower(@$a['device']['model']) < strtolower(@$b['device']['model']) ? -1 : 1;
83-
8471
}
8572

8673
return @$a['device']['brand'] < @$b['device']['brand'] ? -1 : 1;
8774
});
8875

8976
$chunks = array_chunk($fixtures, 500);
9077

91-
foreach($chunks AS $nr => $chunk) {
78+
foreach ($chunks as $nr => $chunk) {
9279
$content = Spyc::YAMLDump($chunk, false, 0);
9380

9481
$content = str_replace(": ON\n", ": 'ON'\n", $content);
@@ -117,14 +104,13 @@
117104

118105
$botFixtures = Spyc::YAMLLoad(file_get_contents(__DIR__ . '/../Tests/fixtures/bots.yml'));
119106

120-
foreach( $botFixtures AS &$fixture) {
107+
foreach ($botFixtures as &$fixture) {
121108
if ($overwrite) {
122109
$fixture = \DeviceDetector\DeviceDetector::getInfoFromUserAgent($fixture['user_agent']);
123110
}
124111
}
125112

126-
usort($botFixtures, function($a, $b) {
127-
113+
usort($botFixtures, function ($a, $b) {
128114
if (empty($b)) {
129115
return -1;
130116
}
@@ -143,4 +129,3 @@
143129
file_put_contents(__DIR__ . '/../Tests/fixtures/bots.yml', Spyc::YAMLDump($botFixtures, false, 0));
144130

145131
echo "done.\n";
146-

misc/statistics.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
require_once(__DIR__.'/../vendor/autoload.php');
1010

11-
if(count($argv) != 2) {
11+
if (count($argv) != 2) {
1212
die("invalid arguments. Useage: php statistics.php filetoparse.txt");
1313
}
1414

@@ -27,7 +27,6 @@
2727

2828
if ($handle) {
2929
while (($line = fgets($handle, 4096)) !== false) {
30-
3130
if (empty($line)) {
3231
continue;
3332
}
@@ -53,7 +52,6 @@
5352
} else {
5453
$unknownDeviceTypes++;
5554
}
56-
5755
}
5856
if (!feof($handle)) {
5957
echo "Error: unexpected fgets() fail\n";
@@ -63,7 +61,8 @@
6361

6462
$timeElapsed = microtime(true) - $startTime;
6563

66-
function getPercentage($cur, $max) {
64+
function getPercentage($cur, $max)
65+
{
6766
return format(round($cur*100/$max), ' ');
6867
}
6968

@@ -110,4 +109,4 @@ function format($str, $length)
110109
format($deviceTypes[9], $parsedUAs), getPercentage($deviceTypes[9], $parsedUAs),
111110
format($deviceTypes[10], $parsedUAs), getPercentage($deviceTypes[10], $parsedUAs),
112111
format($unknownDeviceTypes, $parsedUAs), getPercentage($unknownDeviceTypes, $parsedUAs)
113-
);
112+
);

misc/test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@
3939

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

42-
echo "</pre>";
42+
echo "</pre>";

0 commit comments

Comments
 (0)