Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 74 additions & 6 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ reusable-steps:
- npm-cache-{{ .Revision }}
- npm-cache-{{ .Branch }}
- npm-cache
- &restore-php-cs-fixer-cache
restore_cache:
keys:
- php-cs-fixer-cache-{{ .Revision }}
- php-cs-fixer-cache-{{ .Branch }}
- php-cs-fixer-cache
- &save-composer-cache-by-branch
save_cache:
paths:
Expand All @@ -45,6 +51,16 @@ reusable-steps:
paths:
- ~/.npm
key: npm-cache-{{ .Revision }}-{{ .BuildNum }}
- &save-php-cs-fixer-cache-by-branch
save_cache:
paths:
- .php_cs.cache
key: php-cs-fixer-cache-{{ .Branch }}-{{ .BuildNum }}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

are you sure this is correct?
you never restore using .BuildNum so it seems pointless.
(i'm aware of how circle ci restore_cache works with substrings)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i thought you might
save key:

php-cs-fixer-cache-{{ .Branch }}-{{ .Revision }}

restore keys:

keys:
  - php-cs-fixer-cache-{{ .Branch }}-{{ .Revision }}
  - php-cs-fixer-cache-{{ .Branch }}
  - php-cs-fixer-cache

@teohhanhui teohhanhui Jun 5, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's intentional. The .BuildNum is for cache busting.

@bendavies bendavies Jun 5, 2018

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, in my project i actually generate a hash of all php files they php-cs-fixer runs over, then cache on that.

something like:
find src tests -type f -name "*.php" -exec md5sum {} + > php-cs-fixer.checksum

- restore_cache:
  keys:
    - php-cs-fixer-{{ checksum "php-cs-fixer.checksum" }}
    - php-cs-fixer-
...
- save_cache:
  key: php-cs-fixer-{{ checksum "php-cs-fixer.checksum" }}
  paths:
    - .php_cs.cache

then there is no need for cache busting.

- &save-php-cs-fixer-cache-by-revision
save_cache:
paths:
- .php_cs.cache
key: php-cs-fixer-cache-{{ .Revision }}-{{ .BuildNum }}
- &update-composer
run:
name: Update Composer
Expand All @@ -55,7 +71,55 @@ reusable-steps:
command: composer update --prefer-dist --no-progress --no-suggest --ansi

jobs:
phpunit-php-7.2-coverage:
php-cs-fixer:
docker:
- image: circleci/php:7.2-node-browsers
environment:
PHP_CS_FIXER_FUTURE_MODE: 1
working_directory: ~/api-platform/core
steps:
- checkout
- *restore-composer-cache
- *restore-php-cs-fixer-cache
- *disable-xdebug-php-extension
- *disable-php-memory-limit
- *update-composer
- run:
name: Install PHP-CS-Fixer
command: composer global require friendsofphp/php-cs-fixer:^2.12
- *save-composer-cache-by-revision
- *save-composer-cache-by-branch
- run:
name: Run PHP-CS-Fixer
command: |-
export PATH="$PATH:$HOME/.composer/vendor/bin"
php-cs-fixer fix --dry-run --diff --ansi
- *save-php-cs-fixer-cache-by-revision
- *save-php-cs-fixer-cache-by-branch

phpstan:
docker:
- image: circleci/php:7.2-node-browsers
working_directory: ~/api-platform/core
steps:
- checkout
- *restore-composer-cache
- *disable-xdebug-php-extension
- *disable-php-memory-limit
- *update-composer
- *update-project-dependencies
- run:
name: Install PHPStan
command: composer global require phpstan/phpstan:^0.8
- *save-composer-cache-by-revision
- *save-composer-cache-by-branch
- run:
name: Run PHPStan
command: |-
export PATH="$PATH:$HOME/.composer/vendor/bin"
phpstan analyse -c phpstan.neon -l5 --ansi src tests

phpunit-coverage:
docker:
- image: circleci/php:7.2-node-browsers
environment:
Expand Down Expand Up @@ -98,7 +162,7 @@ jobs:
- *save-npm-cache-by-revision
- *save-npm-cache-by-branch

behat-php-7.2-coverage:
behat-coverage:
docker:
- image: circleci/php:7.2-node-browsers
environment:
Expand Down Expand Up @@ -181,11 +245,15 @@ jobs:

workflows:
version: 2
lint:
jobs:
- php-cs-fixer
- phpstan
test-with-coverage:
jobs:
- phpunit-php-7.2-coverage
- behat-php-7.2-coverage
- phpunit-coverage
- behat-coverage
- merge-and-upload-coverage:
requires:
- phpunit-php-7.2-coverage
- behat-php-7.2-coverage
- phpunit-coverage
- behat-coverage
27 changes: 17 additions & 10 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,23 @@ return PhpCsFixer\Config::create()
'location' => 'after_open',
],
'modernize_types_casting' => true,
'no_extra_consecutive_blank_lines' => [
'break',
'continue',
'curly_brace_block',
'extra',
'parenthesis_brace_block',
'return',
'square_brace_block',
'throw',
'use',
'native_function_invocation' => [
'include' => [
'@compiler_optimized',
],
],
'no_extra_blank_lines' => [
'tokens' => [
'break',
'continue',
'curly_brace_block',
'extra',
'parenthesis_brace_block',
'return',
'square_brace_block',
'throw',
'use',
],
],
'no_useless_else' => true,
'no_useless_return' => true,
Expand Down
32 changes: 5 additions & 27 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ matrix:
- php: '7.0'
- php: '7.1'
- php: '7.2'
- php: '7.2'
env: lint=1
- php: '7.2'
env: deps=low
- php: '7.2'
Expand All @@ -40,12 +38,6 @@ matrix:
before_install:
- phpenv config-rm xdebug.ini || echo "xdebug not available"
- echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- if [[ $lint = 1 ]]; then
wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.12.0/php-cs-fixer.phar;
fi
- if [[ $lint = 1 ]]; then
composer global require --dev 'phpstan/phpstan:^0.8';
fi
- export PATH="$PATH:$HOME/.composer/vendor/bin"

install:
Expand All @@ -56,26 +48,12 @@ install:
fi

script:
- if [[ $lint != 1 ]]; then
tests/Fixtures/app/console cache:clear;
fi
- if [[ $lint != 1 ]]; then
vendor/bin/phpunit;
fi
- if [[ $lint != 1 ]]; then
tests/Fixtures/app/console cache:clear;
fi
- tests/Fixtures/app/console cache:clear
- vendor/bin/phpunit
- tests/Fixtures/app/console cache:clear
- if [[ $APP_ENV = 'postgres' ]]; then
vendor/bin/behat --suite=postgres --format=progress;
elif [[ $lint != 1 ]]; then
else
vendor/bin/behat --suite=default --format=progress;
fi
- if [[ $lint != 1 ]]; then
tests/Fixtures/app/console api:swagger:export > swagger.json && npx swagger-cli validate swagger.json && rm swagger.json;
fi
- if [[ $lint = 1 ]]; then
php php-cs-fixer.phar fix --dry-run --diff --no-ansi;
fi
- if [[ $lint = 1 ]]; then
phpstan analyse -c phpstan.neon -l5 --ansi src tests;
fi
- tests/Fixtures/app/console api:swagger:export > swagger.json && npx swagger-cli validate swagger.json && rm swagger.json
16 changes: 8 additions & 8 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,9 +386,9 @@ public function thereAreDummyObjectsWithDummyDateAndDummyBoolean(int $nb, string
{
$descriptions = ['Smart dummy.', 'Not so smart dummy.'];

if (in_array($bool, ['true', '1', 1], true)) {
if (\in_array($bool, ['true', '1', 1], true)) {
$bool = true;
} elseif (in_array($bool, ['false', '0', 0], true)) {
} elseif (\in_array($bool, ['false', '0', 0], true)) {
$bool = false;
} else {
$expected = ['true', 'false', '1', '0'];
Expand Down Expand Up @@ -496,9 +496,9 @@ public function thereAreDummyObjectsWithDummyPrice(int $nb)
*/
public function thereAreDummyObjectsWithDummyBoolean(int $nb, string $bool)
{
if (in_array($bool, ['true', '1', 1], true)) {
if (\in_array($bool, ['true', '1', 1], true)) {
$bool = true;
} elseif (in_array($bool, ['false', '0', 0], true)) {
} elseif (\in_array($bool, ['false', '0', 0], true)) {
$bool = false;
} else {
$expected = ['true', 'false', '1', '0'];
Expand All @@ -524,9 +524,9 @@ public function thereAreDummyObjectsWithDummyBoolean(int $nb, string $bool)
*/
public function thereAreDummyObjectsWithEmbeddedDummyBoolean(int $nb, string $bool)
{
if (in_array($bool, ['true', '1', 1], true)) {
if (\in_array($bool, ['true', '1', 1], true)) {
$bool = true;
} elseif (in_array($bool, ['false', '0', 0], true)) {
} elseif (\in_array($bool, ['false', '0', 0], true)) {
$bool = false;
} else {
$expected = ['true', 'false', '1', '0'];
Expand All @@ -551,9 +551,9 @@ public function thereAreDummyObjectsWithEmbeddedDummyBoolean(int $nb, string $bo
*/
public function thereAreDummyObjectsWithRelationEmbeddedDummyBoolean(int $nb, string $bool)
{
if (in_array($bool, ['true', '1', 1], true)) {
if (\in_array($bool, ['true', '1', 1], true)) {
$bool = true;
} elseif (in_array($bool, ['false', '0', 0], true)) {
} elseif (\in_array($bool, ['false', '0', 0], true)) {
$bool = false;
} else {
$expected = ['true', 'false', '1', '0'];
Expand Down
4 changes: 2 additions & 2 deletions features/bootstrap/HydraContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,15 +118,15 @@ public function assertOperationNodeValueContains(string $nodeName, string $opera
*/
public function assertNbOperationsExist(int $nb, string $className)
{
Assert::assertEquals($nb, count($this->getOperations($className)));
Assert::assertEquals($nb, \count($this->getOperations($className)));
}

/**
* @Then :nb properties are available for Hydra class :class
*/
public function assertNbPropertiesExist(int $nb, string $className)
{
Assert::assertEquals($nb, count($this->getProperties($className)));
Assert::assertEquals($nb, \count($this->getProperties($className)));
}

/**
Expand Down
4 changes: 2 additions & 2 deletions features/bootstrap/JsonContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public function __construct(HttpCallResultPool $httpCallResultPool)

private function sortArrays($obj)
{
$isObject = is_object($obj);
$isObject = \is_object($obj);

foreach ($obj as $key => $value) {
if (null === $value || is_scalar($value)) {
continue;
}

if (is_array($value)) {
if (\is_array($value)) {
sort($value);
}

Expand Down
2 changes: 1 addition & 1 deletion features/bootstrap/SwaggerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function assertPropertyExist(string $propertyName, string $className)
*/
public function assertPropertyIsRequired(string $propertyName, string $className)
{
if (!in_array($propertyName, $this->getClassInfo($className)->required, true)) {
if (!\in_array($propertyName, $this->getClassInfo($className)->required, true)) {
throw new ExpectationFailedException(sprintf('Property "%s" of class "%s" should be required', $propertyName, $className));
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Bridge/Doctrine/Common/DataPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,6 @@ public function remove($data)
*/
private function getManager($data)
{
return is_object($data) ? $this->managerRegistry->getManagerForClass($this->getObjectClass($data)) : null;
return \is_object($data) ? $this->managerRegistry->getManagerForClass($this->getObjectClass($data)) : null;
}
}
2 changes: 1 addition & 1 deletion src/DataProvider/ChainItemDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getItem(string $resourceClass, $id, string $operationName = null

return $dataProvider->getItem($resourceClass, $id, $operationName, $context);
} catch (ResourceClassNotSupportedException $e) {
@trigger_error(sprintf('Throwing a "%s" is deprecated in favor of implementing "%s"', get_class($e), RestrictedDataProviderInterface::class), E_USER_DEPRECATED);
@trigger_error(sprintf('Throwing a "%s" is deprecated in favor of implementing "%s"', \get_class($e), RestrictedDataProviderInterface::class), E_USER_DEPRECATED);
continue;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ private function getSourcePointerFromViolation(ConstraintViolationInterface $vio
$propertyMetadata = $this->propertyMetadataFactory
->create(
// Im quite sure this requires some thought in case of validations over relationships
get_class($violation->getRoot()),
\get_class($violation->getRoot()),
$fieldName
);

Expand Down
6 changes: 3 additions & 3 deletions src/JsonApi/Serializer/ItemNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function normalize($object, $format = null, array $context = [])
// Get and populate attributes data
$objectAttributesData = parent::normalize($object, $format, $context);

if (!is_array($objectAttributesData)) {
if (!\is_array($objectAttributesData)) {
return $objectAttributesData;
}

Expand Down Expand Up @@ -147,7 +147,7 @@ protected function getAttributes($object, $format = null, array $context)
*/
protected function setAttributeValue($object, $attribute, $value, $format = null, array $context = [])
{
parent::setAttributeValue($object, $attribute, is_array($value) && array_key_exists('data', $value) ? $value['data'] : $value, $format, $context);
parent::setAttributeValue($object, $attribute, \is_array($value) && array_key_exists('data', $value) ? $value['data'] : $value, $format, $context);
}

/**
Expand All @@ -164,7 +164,7 @@ protected function denormalizeRelation(string $attributeName, PropertyMetadata $
return $this->serializer->denormalize($value, $className, $format, $context);
}

if (!is_array($value) || !isset($value['id'], $value['type'])) {
if (!\is_array($value) || !isset($value['id'], $value['type'])) {
throw new InvalidArgumentException('Only resource linkage supported currently, see: http://jsonapi.org/format/#document-resource-object-linkage.');
}

Expand Down
2 changes: 1 addition & 1 deletion src/JsonApi/Serializer/ReservedAttributeNameConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function normalize($propertyName)
*/
public function denormalize($propertyName)
{
if (in_array($propertyName, self::JSON_API_RESERVED_ATTRIBUTES, true)) {
if (\in_array($propertyName, self::JSON_API_RESERVED_ATTRIBUTES, true)) {
$propertyName = substr($propertyName, 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private function normalize(bool $collection, ResourceMetadata $resourceMetadata,
$newOperations = [];
foreach ($operations as $operationName => $operation) {
// e.g.: @ApiResource(itemOperations={"get"})
if (is_int($operationName) && is_string($operation)) {
if (\is_int($operationName) && \is_string($operation)) {
$operationName = $operation;
$operation = [];
}
Expand All @@ -132,7 +132,7 @@ private function normalize(bool $collection, ResourceMetadata $resourceMetadata,
private function normalizeGraphQl(ResourceMetadata $resourceMetadata, array $operations)
{
foreach ($operations as $operationName => $operation) {
if (is_int($operationName) && is_string($operation)) {
if (\is_int($operationName) && \is_string($operation)) {
unset($operations[$operationName]);
$operations[$operation] = [];
}
Expand Down
Loading