Skip to content

Commit 435d445

Browse files
authored
Merge pull request #2004 from teohhanhui/move-lint-jobs-to-circleci
Move lint jobs to CircleCI
2 parents 99f2724 + 3ea9755 commit 435d445

File tree

22 files changed

+132
-79
lines changed

22 files changed

+132
-79
lines changed

.circleci/config.yml

Lines changed: 74 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ reusable-steps:
2525
- npm-cache-{{ .Revision }}
2626
- npm-cache-{{ .Branch }}
2727
- npm-cache
28+
- &restore-php-cs-fixer-cache
29+
restore_cache:
30+
keys:
31+
- php-cs-fixer-cache-{{ .Revision }}
32+
- php-cs-fixer-cache-{{ .Branch }}
33+
- php-cs-fixer-cache
2834
- &save-composer-cache-by-branch
2935
save_cache:
3036
paths:
@@ -45,6 +51,16 @@ reusable-steps:
4551
paths:
4652
- ~/.npm
4753
key: npm-cache-{{ .Revision }}-{{ .BuildNum }}
54+
- &save-php-cs-fixer-cache-by-branch
55+
save_cache:
56+
paths:
57+
- .php_cs.cache
58+
key: php-cs-fixer-cache-{{ .Branch }}-{{ .BuildNum }}
59+
- &save-php-cs-fixer-cache-by-revision
60+
save_cache:
61+
paths:
62+
- .php_cs.cache
63+
key: php-cs-fixer-cache-{{ .Revision }}-{{ .BuildNum }}
4864
- &update-composer
4965
run:
5066
name: Update Composer
@@ -55,7 +71,55 @@ reusable-steps:
5571
command: composer update --prefer-dist --no-progress --no-suggest --ansi
5672

5773
jobs:
58-
phpunit-php-7.2-coverage:
74+
php-cs-fixer:
75+
docker:
76+
- image: circleci/php:7.2-node-browsers
77+
environment:
78+
PHP_CS_FIXER_FUTURE_MODE: 1
79+
working_directory: ~/api-platform/core
80+
steps:
81+
- checkout
82+
- *restore-composer-cache
83+
- *restore-php-cs-fixer-cache
84+
- *disable-xdebug-php-extension
85+
- *disable-php-memory-limit
86+
- *update-composer
87+
- run:
88+
name: Install PHP-CS-Fixer
89+
command: composer global require friendsofphp/php-cs-fixer:^2.12
90+
- *save-composer-cache-by-revision
91+
- *save-composer-cache-by-branch
92+
- run:
93+
name: Run PHP-CS-Fixer
94+
command: |-
95+
export PATH="$PATH:$HOME/.composer/vendor/bin"
96+
php-cs-fixer fix --dry-run --diff --ansi
97+
- *save-php-cs-fixer-cache-by-revision
98+
- *save-php-cs-fixer-cache-by-branch
99+
100+
phpstan:
101+
docker:
102+
- image: circleci/php:7.2-node-browsers
103+
working_directory: ~/api-platform/core
104+
steps:
105+
- checkout
106+
- *restore-composer-cache
107+
- *disable-xdebug-php-extension
108+
- *disable-php-memory-limit
109+
- *update-composer
110+
- *update-project-dependencies
111+
- run:
112+
name: Install PHPStan
113+
command: composer global require phpstan/phpstan:^0.8
114+
- *save-composer-cache-by-revision
115+
- *save-composer-cache-by-branch
116+
- run:
117+
name: Run PHPStan
118+
command: |-
119+
export PATH="$PATH:$HOME/.composer/vendor/bin"
120+
phpstan analyse -c phpstan.neon -l5 --ansi src tests
121+
122+
phpunit-coverage:
59123
docker:
60124
- image: circleci/php:7.2-node-browsers
61125
environment:
@@ -98,7 +162,7 @@ jobs:
98162
- *save-npm-cache-by-revision
99163
- *save-npm-cache-by-branch
100164

101-
behat-php-7.2-coverage:
165+
behat-coverage:
102166
docker:
103167
- image: circleci/php:7.2-node-browsers
104168
environment:
@@ -181,11 +245,15 @@ jobs:
181245

182246
workflows:
183247
version: 2
248+
lint:
249+
jobs:
250+
- php-cs-fixer
251+
- phpstan
184252
test-with-coverage:
185253
jobs:
186-
- phpunit-php-7.2-coverage
187-
- behat-php-7.2-coverage
254+
- phpunit-coverage
255+
- behat-coverage
188256
- merge-and-upload-coverage:
189257
requires:
190-
- phpunit-php-7.2-coverage
191-
- behat-php-7.2-coverage
258+
- phpunit-coverage
259+
- behat-coverage

.php_cs.dist

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,23 @@ return PhpCsFixer\Config::create()
4242
'location' => 'after_open',
4343
],
4444
'modernize_types_casting' => true,
45-
'no_extra_consecutive_blank_lines' => [
46-
'break',
47-
'continue',
48-
'curly_brace_block',
49-
'extra',
50-
'parenthesis_brace_block',
51-
'return',
52-
'square_brace_block',
53-
'throw',
54-
'use',
45+
'native_function_invocation' => [
46+
'include' => [
47+
'@compiler_optimized',
48+
],
49+
],
50+
'no_extra_blank_lines' => [
51+
'tokens' => [
52+
'break',
53+
'continue',
54+
'curly_brace_block',
55+
'extra',
56+
'parenthesis_brace_block',
57+
'return',
58+
'square_brace_block',
59+
'throw',
60+
'use',
61+
],
5562
],
5663
'no_useless_else' => true,
5764
'no_useless_return' => true,

.travis.yml

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ matrix:
1616
- php: '7.0'
1717
- php: '7.1'
1818
- php: '7.2'
19-
- php: '7.2'
20-
env: lint=1
2119
- php: '7.2'
2220
env: deps=low
2321
- php: '7.2'
@@ -40,12 +38,6 @@ matrix:
4038
before_install:
4139
- phpenv config-rm xdebug.ini || echo "xdebug not available"
4240
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
43-
- if [[ $lint = 1 ]]; then
44-
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.12.0/php-cs-fixer.phar;
45-
fi
46-
- if [[ $lint = 1 ]]; then
47-
composer global require --dev 'phpstan/phpstan:^0.8';
48-
fi
4941
- export PATH="$PATH:$HOME/.composer/vendor/bin"
5042

5143
install:
@@ -56,26 +48,12 @@ install:
5648
fi
5749

5850
script:
59-
- if [[ $lint != 1 ]]; then
60-
tests/Fixtures/app/console cache:clear;
61-
fi
62-
- if [[ $lint != 1 ]]; then
63-
vendor/bin/phpunit;
64-
fi
65-
- if [[ $lint != 1 ]]; then
66-
tests/Fixtures/app/console cache:clear;
67-
fi
51+
- tests/Fixtures/app/console cache:clear
52+
- vendor/bin/phpunit
53+
- tests/Fixtures/app/console cache:clear
6854
- if [[ $APP_ENV = 'postgres' ]]; then
6955
vendor/bin/behat --suite=postgres --format=progress;
70-
elif [[ $lint != 1 ]]; then
56+
else
7157
vendor/bin/behat --suite=default --format=progress;
7258
fi
73-
- if [[ $lint != 1 ]]; then
74-
tests/Fixtures/app/console api:swagger:export > swagger.json && npx swagger-cli validate swagger.json && rm swagger.json;
75-
fi
76-
- if [[ $lint = 1 ]]; then
77-
php php-cs-fixer.phar fix --dry-run --diff --no-ansi;
78-
fi
79-
- if [[ $lint = 1 ]]; then
80-
phpstan analyse -c phpstan.neon -l5 --ansi src tests;
81-
fi
59+
- tests/Fixtures/app/console api:swagger:export > swagger.json && npx swagger-cli validate swagger.json && rm swagger.json

features/bootstrap/FeatureContext.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,9 +386,9 @@ public function thereAreDummyObjectsWithDummyDateAndDummyBoolean(int $nb, string
386386
{
387387
$descriptions = ['Smart dummy.', 'Not so smart dummy.'];
388388

389-
if (in_array($bool, ['true', '1', 1], true)) {
389+
if (\in_array($bool, ['true', '1', 1], true)) {
390390
$bool = true;
391-
} elseif (in_array($bool, ['false', '0', 0], true)) {
391+
} elseif (\in_array($bool, ['false', '0', 0], true)) {
392392
$bool = false;
393393
} else {
394394
$expected = ['true', 'false', '1', '0'];
@@ -496,9 +496,9 @@ public function thereAreDummyObjectsWithDummyPrice(int $nb)
496496
*/
497497
public function thereAreDummyObjectsWithDummyBoolean(int $nb, string $bool)
498498
{
499-
if (in_array($bool, ['true', '1', 1], true)) {
499+
if (\in_array($bool, ['true', '1', 1], true)) {
500500
$bool = true;
501-
} elseif (in_array($bool, ['false', '0', 0], true)) {
501+
} elseif (\in_array($bool, ['false', '0', 0], true)) {
502502
$bool = false;
503503
} else {
504504
$expected = ['true', 'false', '1', '0'];
@@ -524,9 +524,9 @@ public function thereAreDummyObjectsWithDummyBoolean(int $nb, string $bool)
524524
*/
525525
public function thereAreDummyObjectsWithEmbeddedDummyBoolean(int $nb, string $bool)
526526
{
527-
if (in_array($bool, ['true', '1', 1], true)) {
527+
if (\in_array($bool, ['true', '1', 1], true)) {
528528
$bool = true;
529-
} elseif (in_array($bool, ['false', '0', 0], true)) {
529+
} elseif (\in_array($bool, ['false', '0', 0], true)) {
530530
$bool = false;
531531
} else {
532532
$expected = ['true', 'false', '1', '0'];
@@ -551,9 +551,9 @@ public function thereAreDummyObjectsWithEmbeddedDummyBoolean(int $nb, string $bo
551551
*/
552552
public function thereAreDummyObjectsWithRelationEmbeddedDummyBoolean(int $nb, string $bool)
553553
{
554-
if (in_array($bool, ['true', '1', 1], true)) {
554+
if (\in_array($bool, ['true', '1', 1], true)) {
555555
$bool = true;
556-
} elseif (in_array($bool, ['false', '0', 0], true)) {
556+
} elseif (\in_array($bool, ['false', '0', 0], true)) {
557557
$bool = false;
558558
} else {
559559
$expected = ['true', 'false', '1', '0'];

features/bootstrap/HydraContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,15 +118,15 @@ public function assertOperationNodeValueContains(string $nodeName, string $opera
118118
*/
119119
public function assertNbOperationsExist(int $nb, string $className)
120120
{
121-
Assert::assertEquals($nb, count($this->getOperations($className)));
121+
Assert::assertEquals($nb, \count($this->getOperations($className)));
122122
}
123123

124124
/**
125125
* @Then :nb properties are available for Hydra class :class
126126
*/
127127
public function assertNbPropertiesExist(int $nb, string $className)
128128
{
129-
Assert::assertEquals($nb, count($this->getProperties($className)));
129+
Assert::assertEquals($nb, \count($this->getProperties($className)));
130130
}
131131

132132
/**

features/bootstrap/JsonContext.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ public function __construct(HttpCallResultPool $httpCallResultPool)
2626

2727
private function sortArrays($obj)
2828
{
29-
$isObject = is_object($obj);
29+
$isObject = \is_object($obj);
3030

3131
foreach ($obj as $key => $value) {
3232
if (null === $value || is_scalar($value)) {
3333
continue;
3434
}
3535

36-
if (is_array($value)) {
36+
if (\is_array($value)) {
3737
sort($value);
3838
}
3939

features/bootstrap/SwaggerContext.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function assertPropertyExist(string $propertyName, string $className)
9090
*/
9191
public function assertPropertyIsRequired(string $propertyName, string $className)
9292
{
93-
if (!in_array($propertyName, $this->getClassInfo($className)->required, true)) {
93+
if (!\in_array($propertyName, $this->getClassInfo($className)->required, true)) {
9494
throw new ExpectationFailedException(sprintf('Property "%s" of class "%s" should be required', $propertyName, $className));
9595
}
9696
}

src/Bridge/Doctrine/Common/DataPersister.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,6 @@ public function remove($data)
8181
*/
8282
private function getManager($data)
8383
{
84-
return is_object($data) ? $this->managerRegistry->getManagerForClass($this->getObjectClass($data)) : null;
84+
return \is_object($data) ? $this->managerRegistry->getManagerForClass($this->getObjectClass($data)) : null;
8585
}
8686
}

src/DataProvider/ChainItemDataProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function getItem(string $resourceClass, $id, string $operationName = null
4646

4747
return $dataProvider->getItem($resourceClass, $id, $operationName, $context);
4848
} catch (ResourceClassNotSupportedException $e) {
49-
@trigger_error(sprintf('Throwing a "%s" is deprecated in favor of implementing "%s"', get_class($e), RestrictedDataProviderInterface::class), E_USER_DEPRECATED);
49+
@trigger_error(sprintf('Throwing a "%s" is deprecated in favor of implementing "%s"', \get_class($e), RestrictedDataProviderInterface::class), E_USER_DEPRECATED);
5050
continue;
5151
}
5252
}

src/JsonApi/Serializer/ConstraintViolationListNormalizer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private function getSourcePointerFromViolation(ConstraintViolationInterface $vio
7171
$propertyMetadata = $this->propertyMetadataFactory
7272
->create(
7373
// Im quite sure this requires some thought in case of validations over relationships
74-
get_class($violation->getRoot()),
74+
\get_class($violation->getRoot()),
7575
$fieldName
7676
);
7777

0 commit comments

Comments
 (0)