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 }}
- &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
48 changes: 27 additions & 21 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

$header = <<<'HEADER'
This file is part of the API Platform project.

Expand All @@ -18,13 +20,7 @@ return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@DoctrineAnnotation' => true,
'doctrine_annotation_array_assignment' => [
'operator' => '=',
],
'doctrine_annotation_spaces' => [
'after_array_assignments_equals' => false,
'before_array_assignments_equals' => false,
],
'@PHPUnit60Migration:risky' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => [
Expand All @@ -34,29 +30,39 @@ return PhpCsFixer\Config::create()
'allow_single_line_closure' => true,
],
'declare_strict_types' => true,
'doctrine_annotation_array_assignment' => [
'operator' => '=',
],
'doctrine_annotation_spaces' => [
'after_array_assignments_equals' => false,
'before_array_assignments_equals' => false,
],
'header_comment' => [
'header' => $header,
'location' => 'after_open',
],
'modernize_types_casting' => true,
// 'native_function_invocation' => 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,
'ordered_imports' => true,
// 'phpdoc_add_missing_param_annotation' => [
// 'only_untyped' => false,
// ],
'phpdoc_order' => true,
'psr4' => true,
'semicolon_after_instruction' => true,
Expand Down
36 changes: 6 additions & 30 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ matrix:
include:
- php: '7.1'
- php: '7.2'
- php: '7.2'
env: lint=1
- php: '7.2'
env: deps=low
- php: '7.2'
Expand All @@ -39,12 +37,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.8.4/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 @@ -55,29 +47,13 @@ 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
tests/Fixtures/app/console api:swagger:export --yaml > swagger.yaml && npx swagger-cli validate --no-schema swagger.yaml && rm swagger.yaml;
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
- tests/Fixtures/app/console api:swagger:export --yaml > swagger.yaml && npx swagger-cli validate --no-schema swagger.yaml && rm swagger.yaml
16 changes: 8 additions & 8 deletions features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,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 @@ -490,9 +490,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 @@ -518,9 +518,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 @@ -545,9 +545,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 @@ -142,15 +142,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
3 changes: 2 additions & 1 deletion features/main/circular_reference.feature
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ Feature: Circular references handling
"@type": "CircularReference",
"parent": "/circular_references/1",
"children": [
"/circular_references/1"
"/circular_references/1",
"/circular_references/2"
]
},
"children": []
Expand Down
4 changes: 4 additions & 0 deletions src/Bridge/Doctrine/Orm/Extension/EagerLoadingExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ private function apply(bool $collection, QueryBuilder $queryBuilder, QueryNameGe
$context += $this->getNormalizationContext($context['resource_class'] ?? $resourceClass, $contextType, $options);
}

if (empty($context[AbstractNormalizer::GROUPS]) && !isset($context[AbstractNormalizer::ATTRIBUTES])) {
return;
}

$this->joinRelations($queryBuilder, $queryNameGenerator, $resourceClass, $forceEager, $fetchPartial, $queryBuilder->getRootAliases()[0], $options, $context);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function collect(Request $request, Response $response, \Exception $except
$filters = [];
foreach ($resourceMetadata ? $resourceMetadata->getAttribute('filters', []) : [] as $id) {
if ($this->filterLocator->has($id)) {
$filters[$id] = get_class($this->filterLocator->get($id));
$filters[$id] = \get_class($this->filterLocator->get($id));
continue;
}

Expand Down
2 changes: 0 additions & 2 deletions src/Hydra/Serializer/CollectionFiltersNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
use ApiPlatform\Core\Api\FilterInterface;
use ApiPlatform\Core\Api\FilterLocatorTrait;
use ApiPlatform\Core\Api\ResourceClassResolverInterface;
use ApiPlatform\Core\JsonLd\Serializer\JsonLdContextTrait;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface;
use Psr\Container\ContainerInterface;
use Symfony\Component\Serializer\Normalizer\CacheableSupportsMethodInterface;
Expand All @@ -31,7 +30,6 @@
*/
final class CollectionFiltersNormalizer implements NormalizerInterface, NormalizerAwareInterface, CacheableSupportsMethodInterface
{
use JsonLdContextTrait;
use FilterLocatorTrait;

private $collectionNormalizer;
Expand Down
Loading