From 7b7f6c474d404946a7902d7a8f2db676456d9199 Mon Sep 17 00:00:00 2001 From: PabloKowalczyk <11366345+PabloKowalczyk@users.noreply.github.com> Date: Mon, 12 Dec 2022 14:20:53 +0100 Subject: [PATCH 1/3] Update and lock PHPCSFixer to v3.13.* --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 205e3cf..829cd8f 100644 --- a/composer.json +++ b/composer.json @@ -31,7 +31,7 @@ }, "require-dev": { "ergebnis/composer-normalize": "^2.28", - "friendsofphp/php-cs-fixer": "^3.8", + "friendsofphp/php-cs-fixer": "3.13.*", "mockery/mockery": "^1.0", "phpmd/phpmd": "^2.6", "phpstan/phpstan": "^1.7", From ae4dc7725057756f9eb434663d5f4575806cf9f9 Mon Sep 17 00:00:00 2001 From: PabloKowalczyk <11366345+PabloKowalczyk@users.noreply.github.com> Date: Mon, 12 Dec 2022 14:20:59 +0100 Subject: [PATCH 2/3] CS fixes --- src/Encoder/Encoder.php | 3 --- src/Exceptions/BaseJsonApiException.php | 4 +--- src/Exceptions/JsonApiException.php | 3 +-- src/Http/Headers/AcceptMediaType.php | 3 +-- src/Parser/IdentifierAndResource.php | 4 ++-- src/Parser/Parser.php | 7 +++--- .../ParseRelationshipDataTrait.php | 8 +++---- .../RelationshipDataIsCollection.php | 1 + .../RelationshipDataIsIdentifier.php | 1 + .../RelationshipDataIsNull.php | 1 + .../RelationshipDataIsResource.php | 1 + src/Schema/ErrorCollection.php | 9 ++------ src/Schema/SchemaContainer.php | 6 ++--- tests/BaseTestCase.php | 3 +-- tests/Data/Collection.php | 8 ++----- tests/Data/Models/Author.php | 4 +--- tests/Data/Models/AuthorCModel.php | 8 ++----- tests/Data/Models/Comment.php | 4 +--- tests/Data/Models/Post.php | 4 +--- tests/Data/Models/Site.php | 4 +--- tests/Data/Schemas/DevSchema.php | 7 +++--- tests/Encoder/EncodeSimpleObjectsTest.php | 3 +-- .../Encoder/EncodeSparseAndFieldSetsTest.php | 2 +- tests/Encoder/EncoderTest.php | 5 ++--- .../Issue154/CustomContainerInterface.php | 3 +-- .../Issue154/CustomEncoderInterface.php | 3 +-- tests/Extensions/Issue169/CustomEncoder.php | 5 ++--- .../Extensions/Issue47/CustomFieldsFilter.php | 3 +-- tests/Http/Query/BaseQueryParserTest.php | 5 ++--- tests/Http/ResponsesTest.php | 22 +++++++++---------- tests/I18n/MessagesTest.php | 1 + tests/Parser/RelationshipDataTest.php | 6 ++--- 32 files changed, 57 insertions(+), 94 deletions(-) diff --git a/src/Encoder/Encoder.php b/src/Encoder/Encoder.php index a8d92c6..4289865 100644 --- a/src/Encoder/Encoder.php +++ b/src/Encoder/Encoder.php @@ -314,9 +314,6 @@ protected function encodeErrorsToArray(iterable $errors): array return $array; } - /** - * @param $meta - */ protected function encodeMetaToArray($meta): array { $this->withMeta($meta); diff --git a/src/Exceptions/BaseJsonApiException.php b/src/Exceptions/BaseJsonApiException.php index bf38050..d976874 100644 --- a/src/Exceptions/BaseJsonApiException.php +++ b/src/Exceptions/BaseJsonApiException.php @@ -20,8 +20,6 @@ * limitations under the License. */ -use RuntimeException; - -abstract class BaseJsonApiException extends RuntimeException +abstract class BaseJsonApiException extends \RuntimeException { } diff --git a/src/Exceptions/JsonApiException.php b/src/Exceptions/JsonApiException.php index eacc351..3d97091 100644 --- a/src/Exceptions/JsonApiException.php +++ b/src/Exceptions/JsonApiException.php @@ -20,7 +20,6 @@ * limitations under the License. */ -use Exception; use Neomerx\JsonApi\Contracts\Schema\ErrorInterface; use Neomerx\JsonApi\Schema\ErrorCollection; @@ -57,7 +56,7 @@ class JsonApiException extends BaseJsonApiException * @SuppressWarnings(PHPMD.StaticAccess) * @SuppressWarnings(PHPMD.ElseExpression) */ - public function __construct($errors, int $httpCode = self::DEFAULT_HTTP_CODE, Exception $previous = null) + public function __construct($errors, int $httpCode = self::DEFAULT_HTTP_CODE, \Exception $previous = null) { parent::__construct('JSON API error', 0, $previous); diff --git a/src/Http/Headers/AcceptMediaType.php b/src/Http/Headers/AcceptMediaType.php index b8bf9ef..1ed22bd 100644 --- a/src/Http/Headers/AcceptMediaType.php +++ b/src/Http/Headers/AcceptMediaType.php @@ -20,7 +20,6 @@ * limitations under the License. */ -use Closure; use Neomerx\JsonApi\Contracts\Http\Headers\AcceptMediaTypeInterface; use Neomerx\JsonApi\Exceptions\InvalidArgumentException; @@ -76,7 +75,7 @@ public function getQuality(): float return $this->quality; } - public static function getCompare(): Closure + public static function getCompare(): \Closure { return function (AcceptMediaTypeInterface $lhs, AcceptMediaTypeInterface $rhs) { $qualityCompare = self::compareQuality($lhs->getQuality(), $rhs->getQuality()); diff --git a/src/Parser/IdentifierAndResource.php b/src/Parser/IdentifierAndResource.php index 7e9f61f..da9dd9f 100644 --- a/src/Parser/IdentifierAndResource.php +++ b/src/Parser/IdentifierAndResource.php @@ -186,7 +186,7 @@ public function getRelationships(): iterable \assert( $hasData || $hasMeta || $hasLinks, - "Relationship `${name}` for type `" . $this->getType() . + "Relationship `{$name}` for type `" . $this->getType() . '` MUST contain at least one of the following: links, data or meta.' ); @@ -270,7 +270,7 @@ private function assertRelationshipNameAndDescription(string $name, array $descr ); \assert( true === \is_array($description) && false === empty($description), - "Relationship `${name}` for type `" . $this->getType() . '` should be a non-empty array.' + "Relationship `{$name}` for type `" . $this->getType() . '` should be a non-empty array.' ); return true; diff --git a/src/Parser/Parser.php b/src/Parser/Parser.php index 4463aba..bfccdcf 100644 --- a/src/Parser/Parser.php +++ b/src/Parser/Parser.php @@ -20,7 +20,6 @@ * limitations under the License. */ -use IteratorAggregate; use Neomerx\JsonApi\Contracts\Factories\FactoryInterface; use Neomerx\JsonApi\Contracts\Parser\DocumentDataInterface; use Neomerx\JsonApi\Contracts\Parser\EditableContextInterface; @@ -33,8 +32,8 @@ use Neomerx\JsonApi\Contracts\Schema\PositionInterface; use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface; use Neomerx\JsonApi\Exceptions\InvalidArgumentException; + use function Neomerx\JsonApi\I18n\format as _; -use Traversable; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -104,8 +103,8 @@ public function parse($data, array $paths = []): iterable } elseif (true === \is_array($data)) { yield $this->createDocumentDataIsCollection($rootPosition); yield from $this->parseAsResourcesOrIdentifiers($rootPosition, $data); - } elseif ($data instanceof Traversable) { - $data = $data instanceof IteratorAggregate ? $data->getIterator() : $data; + } elseif ($data instanceof \Traversable) { + $data = $data instanceof \IteratorAggregate ? $data->getIterator() : $data; yield $this->createDocumentDataIsCollection($rootPosition); yield from $this->parseAsResourcesOrIdentifiers($rootPosition, $data); } elseif (null === $data) { diff --git a/src/Parser/RelationshipData/ParseRelationshipDataTrait.php b/src/Parser/RelationshipData/ParseRelationshipDataTrait.php index 44d3b94..a8cf72b 100644 --- a/src/Parser/RelationshipData/ParseRelationshipDataTrait.php +++ b/src/Parser/RelationshipData/ParseRelationshipDataTrait.php @@ -20,7 +20,6 @@ * limitations under the License. */ -use IteratorAggregate; use Neomerx\JsonApi\Contracts\Factories\FactoryInterface; use Neomerx\JsonApi\Contracts\Parser\EditableContextInterface; use Neomerx\JsonApi\Contracts\Parser\RelationshipDataInterface; @@ -29,9 +28,10 @@ use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface; use Neomerx\JsonApi\Contracts\Schema\SchemaInterface; use Neomerx\JsonApi\Exceptions\InvalidArgumentException; + use function Neomerx\JsonApi\I18n\format as _; + use Neomerx\JsonApi\Parser\IdentifierAndResource; -use Traversable; trait ParseRelationshipDataTrait { @@ -98,12 +98,12 @@ private function parseData( return $factory->createRelationshipDataIsIdentifier($container, $context, $position, $data); } elseif (true === \is_array($data)) { return $factory->createRelationshipDataIsCollection($container, $context, $position, $data); - } elseif ($data instanceof Traversable) { + } elseif ($data instanceof \Traversable) { return $factory->createRelationshipDataIsCollection( $container, $context, $position, - $data instanceof IteratorAggregate ? $data->getIterator() : $data + $data instanceof \IteratorAggregate ? $data->getIterator() : $data ); } elseif (null === $data) { return $factory->createRelationshipDataIsNull(); diff --git a/src/Parser/RelationshipData/RelationshipDataIsCollection.php b/src/Parser/RelationshipData/RelationshipDataIsCollection.php index 9990ed7..3836d22 100644 --- a/src/Parser/RelationshipData/RelationshipDataIsCollection.php +++ b/src/Parser/RelationshipData/RelationshipDataIsCollection.php @@ -29,6 +29,7 @@ use Neomerx\JsonApi\Contracts\Schema\PositionInterface; use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface; use Neomerx\JsonApi\Exceptions\LogicException; + use function Neomerx\JsonApi\I18n\format as _; class RelationshipDataIsCollection extends BaseRelationshipData implements RelationshipDataInterface diff --git a/src/Parser/RelationshipData/RelationshipDataIsIdentifier.php b/src/Parser/RelationshipData/RelationshipDataIsIdentifier.php index 2f51842..99f438b 100644 --- a/src/Parser/RelationshipData/RelationshipDataIsIdentifier.php +++ b/src/Parser/RelationshipData/RelationshipDataIsIdentifier.php @@ -29,6 +29,7 @@ use Neomerx\JsonApi\Contracts\Schema\PositionInterface; use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface; use Neomerx\JsonApi\Exceptions\LogicException; + use function Neomerx\JsonApi\I18n\format as _; class RelationshipDataIsIdentifier extends BaseRelationshipData implements RelationshipDataInterface diff --git a/src/Parser/RelationshipData/RelationshipDataIsNull.php b/src/Parser/RelationshipData/RelationshipDataIsNull.php index e540cd1..04aea74 100644 --- a/src/Parser/RelationshipData/RelationshipDataIsNull.php +++ b/src/Parser/RelationshipData/RelationshipDataIsNull.php @@ -24,6 +24,7 @@ use Neomerx\JsonApi\Contracts\Parser\RelationshipDataInterface; use Neomerx\JsonApi\Contracts\Parser\ResourceInterface; use Neomerx\JsonApi\Exceptions\LogicException; + use function Neomerx\JsonApi\I18n\format as _; class RelationshipDataIsNull implements RelationshipDataInterface diff --git a/src/Parser/RelationshipData/RelationshipDataIsResource.php b/src/Parser/RelationshipData/RelationshipDataIsResource.php index bdd36e9..232b26b 100644 --- a/src/Parser/RelationshipData/RelationshipDataIsResource.php +++ b/src/Parser/RelationshipData/RelationshipDataIsResource.php @@ -28,6 +28,7 @@ use Neomerx\JsonApi\Contracts\Schema\PositionInterface; use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface; use Neomerx\JsonApi\Exceptions\LogicException; + use function Neomerx\JsonApi\I18n\format as _; class RelationshipDataIsResource extends BaseRelationshipData implements RelationshipDataInterface diff --git a/src/Schema/ErrorCollection.php b/src/Schema/ErrorCollection.php index 5057a28..89b45f5 100644 --- a/src/Schema/ErrorCollection.php +++ b/src/Schema/ErrorCollection.php @@ -20,20 +20,15 @@ * limitations under the License. */ -use ArrayAccess; -use ArrayIterator; -use Countable; -use IteratorAggregate; use Neomerx\JsonApi\Contracts\Schema\DocumentInterface; use Neomerx\JsonApi\Contracts\Schema\ErrorInterface; use Neomerx\JsonApi\Contracts\Schema\LinkInterface; -use Serializable; /** * @SuppressWarnings(PHPMD.TooManyPublicMethods) * @SuppressWarnings(PHPMD.BooleanArgumentFlag) */ -class ErrorCollection implements IteratorAggregate, ArrayAccess, Serializable, Countable +class ErrorCollection implements \IteratorAggregate, \ArrayAccess, \Serializable, \Countable { private array $items = []; @@ -52,7 +47,7 @@ public function __unserialize(array $data): void */ public function getIterator(): \Traversable { - return new ArrayIterator($this->items); + return new \ArrayIterator($this->items); } /** diff --git a/src/Schema/SchemaContainer.php b/src/Schema/SchemaContainer.php index e039818..4e472fa 100644 --- a/src/Schema/SchemaContainer.php +++ b/src/Schema/SchemaContainer.php @@ -20,11 +20,11 @@ * limitations under the License. */ -use Closure; use Neomerx\JsonApi\Contracts\Factories\FactoryInterface; use Neomerx\JsonApi\Contracts\Schema\SchemaContainerInterface; use Neomerx\JsonApi\Contracts\Schema\SchemaInterface; use Neomerx\JsonApi\Exceptions\InvalidArgumentException; + use function Neomerx\JsonApi\I18n\format as _; class SchemaContainer implements SchemaContainerInterface @@ -62,7 +62,7 @@ public function __construct(FactoryInterface $factory, iterable $schemas) /** * Register provider for resource type. * - * @param string|Closure $schema + * @param string|\Closure $schema * * @SuppressWarnings(PHPMD.StaticAccess) * @SuppressWarnings(PHPMD.ElseExpression) @@ -171,7 +171,7 @@ protected function getProviderMapping(string $type) } /** - * @param string|Closure $schema + * @param string|\Closure $schema */ protected function setProviderMapping(string $type, $schema): void { diff --git a/tests/BaseTestCase.php b/tests/BaseTestCase.php index d6cb5e6..bb698ef 100644 --- a/tests/BaseTestCase.php +++ b/tests/BaseTestCase.php @@ -20,7 +20,6 @@ * limitations under the License. */ -use Mockery; use Neomerx\JsonApi\Contracts\Factories\FactoryInterface; use Neomerx\JsonApi\Factories\Factory; use PHPUnit\Framework\TestCase; @@ -33,7 +32,7 @@ abstract class BaseTestCase extends TestCase protected function tearDown(): void { parent::tearDown(); - Mockery::close(); + \Mockery::close(); } protected function createFactory(): FactoryInterface diff --git a/tests/Data/Collection.php b/tests/Data/Collection.php index 0642406..10953ca 100644 --- a/tests/Data/Collection.php +++ b/tests/Data/Collection.php @@ -20,11 +20,7 @@ * limitations under the License. */ -use ArrayAccess; -use ArrayIterator; -use IteratorAggregate; - -class Collection implements ArrayAccess, IteratorAggregate +class Collection implements \ArrayAccess, \IteratorAggregate { private array $data = []; @@ -63,6 +59,6 @@ public function offsetUnset($offset): void */ public function getIterator(): \Traversable { - return new ArrayIterator($this->data); + return new \ArrayIterator($this->data); } } diff --git a/tests/Data/Models/Author.php b/tests/Data/Models/Author.php index 6b994ad..16157d8 100644 --- a/tests/Data/Models/Author.php +++ b/tests/Data/Models/Author.php @@ -20,9 +20,7 @@ * limitations under the License. */ -use stdClass; - -class Author extends stdClass +class Author extends \stdClass { public const ATTRIBUTE_ID = 'author_id'; public const ATTRIBUTE_FIRST_NAME = 'first_name'; diff --git a/tests/Data/Models/AuthorCModel.php b/tests/Data/Models/AuthorCModel.php index cecfd41..9689ce2 100644 --- a/tests/Data/Models/AuthorCModel.php +++ b/tests/Data/Models/AuthorCModel.php @@ -20,11 +20,7 @@ * limitations under the License. */ -use ArrayAccess; -use ArrayIterator; -use IteratorAggregate; - -class AuthorCModel implements ArrayAccess, IteratorAggregate +class AuthorCModel implements \ArrayAccess, \IteratorAggregate { public const ATTRIBUTE_ID = 'author_id'; public const ATTRIBUTE_FIRST_NAME = 'first_name'; @@ -52,7 +48,7 @@ public function __construct(int $identity, string $firstName, string $lastName, */ public function getIterator(): \Traversable { - return new ArrayIterator($this->properties); + return new \ArrayIterator($this->properties); } /** diff --git a/tests/Data/Models/Comment.php b/tests/Data/Models/Comment.php index 3ce342b..6d9094a 100644 --- a/tests/Data/Models/Comment.php +++ b/tests/Data/Models/Comment.php @@ -20,9 +20,7 @@ * limitations under the License. */ -use stdClass; - -class Comment extends stdClass +class Comment extends \stdClass { public const ATTRIBUTE_ID = 'comment_id'; public const ATTRIBUTE_BODY = 'body'; diff --git a/tests/Data/Models/Post.php b/tests/Data/Models/Post.php index 69e46aa..e79d2e2 100644 --- a/tests/Data/Models/Post.php +++ b/tests/Data/Models/Post.php @@ -20,9 +20,7 @@ * limitations under the License. */ -use stdClass; - -class Post extends stdClass +class Post extends \stdClass { public const ATTRIBUTE_ID = 'post_id'; public const ATTRIBUTE_TITLE = 'title'; diff --git a/tests/Data/Models/Site.php b/tests/Data/Models/Site.php index d1b4020..6fe676f 100644 --- a/tests/Data/Models/Site.php +++ b/tests/Data/Models/Site.php @@ -20,9 +20,7 @@ * limitations under the License. */ -use stdClass; - -class Site extends stdClass +class Site extends \stdClass { public const ATTRIBUTE_ID = 'site_id'; public const ATTRIBUTE_NAME = 'name'; diff --git a/tests/Data/Schemas/DevSchema.php b/tests/Data/Schemas/DevSchema.php index 3766a2e..508e13e 100644 --- a/tests/Data/Schemas/DevSchema.php +++ b/tests/Data/Schemas/DevSchema.php @@ -20,7 +20,6 @@ * limitations under the License. */ -use Closure; use Neomerx\JsonApi\Contracts\Schema\LinkInterface; use Neomerx\JsonApi\Schema\BaseSchema; @@ -36,7 +35,7 @@ abstract class DevSchema extends BaseSchema private array $relationshipToRemove = []; /** - * @var Closure + * @var \Closure */ private $resourceLinksClosure = null; @@ -52,7 +51,7 @@ public function getLinks($resource): array return $linksClosure($resource); } - public function setResourceLinksClosure(Closure $linksClosure): void + public function setResourceLinksClosure(\Closure $linksClosure): void { $this->resourceLinksClosure = $linksClosure; } @@ -157,7 +156,7 @@ protected function fixDescriptions($resource, array $descriptions): array foreach ($this->addToRelationship as [$name, $key, $value]) { if (self::RELATIONSHIP_LINKS === $key) { foreach ($value as $linkKey => $linkOrClosure) { - $link = $linkOrClosure instanceof Closure ? $linkOrClosure( + $link = $linkOrClosure instanceof \Closure ? $linkOrClosure( $this, $resource ) : $linkOrClosure; diff --git a/tests/Encoder/EncodeSimpleObjectsTest.php b/tests/Encoder/EncodeSimpleObjectsTest.php index 0969b0a..e0a3b23 100644 --- a/tests/Encoder/EncodeSimpleObjectsTest.php +++ b/tests/Encoder/EncodeSimpleObjectsTest.php @@ -20,7 +20,6 @@ * limitations under the License. */ -use ArrayIterator; use Neomerx\JsonApi\Encoder\Encoder; use Neomerx\JsonApi\Factories\Factory; use Neomerx\JsonApi\Schema\Link; @@ -94,7 +93,7 @@ public function test_encode_empty_iterator(): void ] ); - $actual = $encoder->encodeData(new ArrayIterator([])); + $actual = $encoder->encodeData(new \ArrayIterator([])); $expected = <<withUrlPrefix('http://example.com'); // iterator here - $author->{Author::LINK_COMMENTS} = new ArrayIterator( + $author->{Author::LINK_COMMENTS} = new \ArrayIterator( [ 'comment1' => Comment::instance(5, 'First!'), 'comment2' => Comment::instance(12, 'I like XML better'), @@ -646,7 +645,7 @@ public function test_encode_traversable_objects_with_attributes_only(): void ); // and iterator here - $itemSet = new ArrayIterator(['what_if_its_not_zero_based_array' => $author]); + $itemSet = new \ArrayIterator(['what_if_its_not_zero_based_array' => $author]); $actual = $encoder->encodeData($itemSet); $expected = << $value) { - $result[$key] = $value instanceof Generator ? $this->iterableToArray($value) : $value; + $result[$key] = $value instanceof \Generator ? $this->iterableToArray($value) : $value; } return $result; @@ -457,7 +456,7 @@ private function iterableToArray(iterable $iterable): array $result = []; foreach ($iterable as $key => $value) { - $result[$key] = $value instanceof Generator ? $this->iterableToArray($value) : $value; + $result[$key] = $value instanceof \Generator ? $this->iterableToArray($value) : $value; } return $result; diff --git a/tests/Http/ResponsesTest.php b/tests/Http/ResponsesTest.php index 65c2979..381b7db 100644 --- a/tests/Http/ResponsesTest.php +++ b/tests/Http/ResponsesTest.php @@ -20,7 +20,6 @@ * limitations under the License. */ -use Mockery; use Mockery\MockInterface; use Neomerx\JsonApi\Contracts\Encoder\EncoderInterface; use Neomerx\JsonApi\Http\BaseResponses; @@ -28,7 +27,6 @@ use Neomerx\JsonApi\Schema\Error; use Neomerx\JsonApi\Schema\ErrorCollection; use Neomerx\Tests\JsonApi\BaseTestCase; -use stdClass; class ResponsesTest extends BaseTestCase { @@ -43,7 +41,7 @@ protected function setUp(): void { parent::setUp(); - $this->mock = Mockery::mock(BaseResponses::class)->makePartial()->shouldAllowMockingProtectedMethods(); + $this->mock = \Mockery::mock(BaseResponses::class)->makePartial()->shouldAllowMockingProtectedMethods(); $this->responses = $this->mock; } @@ -62,7 +60,7 @@ public function test_code_response_has_no_content_type_header(): void */ public function test_content_response1(): void { - $data = new stdClass(); + $data = new \stdClass(); $this->willBeCalledGetMediaType('some', 'type'); $this->willBeCalledEncoderForData($data, 'some json api'); $headers = [BaseResponses::HEADER_CONTENT_TYPE => 'some/type']; @@ -75,7 +73,7 @@ public function test_content_response1(): void */ public function test_content_response2(): void { - $data = new stdClass(); + $data = new \stdClass(); $this->willBeCalledGetMediaType('some', 'type'); $this->willBeCalledEncoderForData($data, 'some json api'); $headers = [BaseResponses::HEADER_CONTENT_TYPE => 'some/type', 'X-Custom' => 'Custom-Header']; @@ -97,7 +95,7 @@ public function test_content_response2(): void */ public function test_created_response1(): void { - $resource = new stdClass(); + $resource = new \stdClass(); $location = 'http://server.tld/resource-type/123'; $this->willBeCalledGetMediaType('some', 'type'); $this->willBeCalledEncoderForData($resource, 'some json api'); @@ -114,7 +112,7 @@ public function test_created_response1(): void */ public function test_created_response2(): void { - $resource = new stdClass(); + $resource = new \stdClass(); $location = 'http://server.tld'; $this->willBeCalledGetMediaType('some', 'type'); $this->willBeCalledEncoderForData($resource, 'some json api'); @@ -141,7 +139,7 @@ public function test_created_response2(): void */ public function test_meta_response1(): void { - $meta = new stdClass(); + $meta = new \stdClass(); $this->willBeCalledGetMediaType('some', 'type'); $this->willBeCalledEncoderForMeta($meta, 'some json api'); $headers = [BaseResponses::HEADER_CONTENT_TYPE => 'some/type']; @@ -154,7 +152,7 @@ public function test_meta_response1(): void */ public function test_meta_response2(): void { - $meta = new stdClass(); + $meta = new \stdClass(); $this->willBeCalledGetMediaType('some', 'type'); $this->willBeCalledEncoderForMeta($meta, 'some json api'); $headers = [BaseResponses::HEADER_CONTENT_TYPE => 'some/type', 'X-Custom' => 'Custom-Header']; @@ -176,7 +174,7 @@ public function test_meta_response2(): void */ public function test_identifiers_response1(): void { - $data = new stdClass(); + $data = new \stdClass(); $this->willBeCalledGetMediaType('some', 'type'); $this->willBeCalledEncoderForIdentifiers($data, 'some json api'); $headers = [BaseResponses::HEADER_CONTENT_TYPE => 'some/type']; @@ -189,7 +187,7 @@ public function test_identifiers_response1(): void */ public function test_identifiers_response2(): void { - $data = new stdClass(); + $data = new \stdClass(); $this->willBeCalledGetMediaType('some', 'type'); $this->willBeCalledEncoderForIdentifiers($data, 'some json api'); $headers = [BaseResponses::HEADER_CONTENT_TYPE => 'some/type', 'X-Custom' => 'Custom-Header']; @@ -288,7 +286,7 @@ private function willBeCalledCreateResponse(?string $content, int $httpCode, arr private function willBeCalledGetEncoder(): MockInterface { - $encoderMock = Mockery::mock(EncoderInterface::class); + $encoderMock = \Mockery::mock(EncoderInterface::class); /* @noinspection PhpMethodParametersCountMismatchInspection */ $this->mock->shouldReceive('getEncoder')->once()->withNoArgs()->andReturn($encoderMock); diff --git a/tests/I18n/MessagesTest.php b/tests/I18n/MessagesTest.php index ae7e1b4..2c49a1f 100644 --- a/tests/I18n/MessagesTest.php +++ b/tests/I18n/MessagesTest.php @@ -21,6 +21,7 @@ */ use function Neomerx\JsonApi\I18n\format as _; + use Neomerx\JsonApi\I18n\Messages; use Neomerx\Tests\JsonApi\BaseTestCase; diff --git a/tests/Parser/RelationshipDataTest.php b/tests/Parser/RelationshipDataTest.php index dcf07c8..14e009a 100644 --- a/tests/Parser/RelationshipDataTest.php +++ b/tests/Parser/RelationshipDataTest.php @@ -20,7 +20,6 @@ * limitations under the License. */ -use Mockery; use Neomerx\JsonApi\Contracts\Parser\ParserInterface; use Neomerx\JsonApi\Contracts\Parser\RelationshipDataInterface; use Neomerx\JsonApi\Contracts\Schema\IdentifierInterface; @@ -30,7 +29,6 @@ use Neomerx\JsonApi\Parser\RelationshipData\RelationshipDataIsNull; use Neomerx\JsonApi\Parser\RelationshipData\RelationshipDataIsResource; use Neomerx\Tests\JsonApi\BaseTestCase; -use stdClass; class RelationshipDataTest extends BaseTestCase { @@ -56,7 +54,7 @@ public function test_is_identifier(): void { $data = $this->createRelationshipData( RelationshipDataIsIdentifier::class, - Mockery::mock(IdentifierInterface::class) + \Mockery::mock(IdentifierInterface::class) ); $this->assertFalse($data->isCollection()); @@ -95,7 +93,7 @@ public function test_is_resource(): void { $data = $this->createRelationshipData( RelationshipDataIsResource::class, - new stdClass() + new \stdClass() ); $this->assertFalse($data->isCollection()); From 7de10d310da9f4c5a247693f84e7dedaa03f61be Mon Sep 17 00:00:00 2001 From: PabloKowalczyk <11366345+PabloKowalczyk@users.noreply.github.com> Date: Mon, 12 Dec 2022 14:25:28 +0100 Subject: [PATCH 3/3] Regenerate PHPStan baseline --- phpstan-baseline.neon | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 6fb2be5..a2ed8f0 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1106,7 +1106,7 @@ parameters: path: src/Representation/BaseWriter.php - - message: "#^Call to function assert\\(\\) with true and non\\-empty\\-string will always evaluate to true\\.$#" + message: "#^Call to function assert\\(\\) with true and non\\-falsy\\-string will always evaluate to true\\.$#" count: 4 path: src/Representation/DocumentWriter.php @@ -1176,7 +1176,7 @@ parameters: path: src/Representation/DocumentWriter.php - - message: "#^Strict comparison using \\!\\=\\= between false and string will always evaluate to true\\.$#" + message: "#^Strict comparison using \\!\\=\\= between false and non\\-empty\\-string will always evaluate to true\\.$#" count: 4 path: src/Representation/DocumentWriter.php @@ -1257,7 +1257,7 @@ parameters: - message: "#^Cannot access offset string on iterable\\|null\\.$#" - count: 2 + count: 1 path: src/Schema/Error.php - @@ -1481,7 +1481,7 @@ parameters: path: src/Schema/SchemaContainer.php - - message: "#^Parameter \\#2 \\$haystack of function in_array expects array, array\\\\|false given\\.$#" + message: "#^Parameter \\#2 \\$haystack of function in_array expects array, array\\\\|false given\\.$#" count: 1 path: src/Schema/SchemaContainer.php @@ -2156,52 +2156,52 @@ parameters: path: tests/Http/Query/BaseQueryParserTest.php - - message: "#^Method class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:280\\:\\:getFields\\(\\) return type has no value type specified in iterable type array\\.$#" + message: "#^Method class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:279\\:\\:getFields\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Http/Query/BaseQueryParserTest.php - - message: "#^Method class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:280\\:\\:getIncludes\\(\\) return type has no value type specified in iterable type array\\.$#" + message: "#^Method class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:279\\:\\:getIncludes\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Http/Query/BaseQueryParserTest.php - - message: "#^Method class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:280\\:\\:getProfileUrls\\(\\) return type has no value type specified in iterable type array\\.$#" + message: "#^Method class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:279\\:\\:getProfileUrls\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Http/Query/BaseQueryParserTest.php - - message: "#^Method class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:280\\:\\:getSorts\\(\\) return type has no value type specified in iterable type array\\.$#" + message: "#^Method class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:279\\:\\:getSorts\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Http/Query/BaseQueryParserTest.php - - message: "#^Method class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:280\\:\\:iterableToArray\\(\\) has parameter \\$iterable with no value type specified in iterable type iterable\\.$#" + message: "#^Method class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:279\\:\\:iterableToArray\\(\\) has parameter \\$iterable with no value type specified in iterable type iterable\\.$#" count: 1 path: tests/Http/Query/BaseQueryParserTest.php - - message: "#^Method class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:280\\:\\:iterableToArray\\(\\) return type has no value type specified in iterable type array\\.$#" + message: "#^Method class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:279\\:\\:iterableToArray\\(\\) return type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Http/Query/BaseQueryParserTest.php - - message: "#^Property class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:280\\:\\:\\$fields type has no value type specified in iterable type array\\.$#" + message: "#^Property class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:279\\:\\:\\$fields type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Http/Query/BaseQueryParserTest.php - - message: "#^Property class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:280\\:\\:\\$includes type has no value type specified in iterable type array\\.$#" + message: "#^Property class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:279\\:\\:\\$includes type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Http/Query/BaseQueryParserTest.php - - message: "#^Property class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:280\\:\\:\\$profile type has no value type specified in iterable type array\\.$#" + message: "#^Property class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:279\\:\\:\\$profile type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Http/Query/BaseQueryParserTest.php - - message: "#^Property class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:280\\:\\:\\$sorts type has no value type specified in iterable type array\\.$#" + message: "#^Property class@anonymous/tests/Http/Query/BaseQueryParserTest\\.php\\:279\\:\\:\\$sorts type has no value type specified in iterable type array\\.$#" count: 1 path: tests/Http/Query/BaseQueryParserTest.php