Skip to content

Commit

Permalink
CS fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
PabloKowalczyk committed Nov 30, 2022
1 parent c70af36 commit 207c903
Show file tree
Hide file tree
Showing 32 changed files with 57 additions and 94 deletions.
3 changes: 0 additions & 3 deletions src/Encoder/Encoder.php
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,6 @@ protected function encodeErrorsToArray(iterable $errors): array
return $array;
}

/**
* @param $meta
*/
protected function encodeMetaToArray($meta): array
{
$this->withMeta($meta);
Expand Down
4 changes: 1 addition & 3 deletions src/Exceptions/BaseJsonApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
* limitations under the License.
*/

use RuntimeException;

abstract class BaseJsonApiException extends RuntimeException
abstract class BaseJsonApiException extends \RuntimeException
{
}
3 changes: 1 addition & 2 deletions src/Exceptions/JsonApiException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* limitations under the License.
*/

use Exception;
use Neomerx\JsonApi\Contracts\Schema\ErrorInterface;
use Neomerx\JsonApi\Schema\ErrorCollection;

Expand Down Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions src/Http/Headers/AcceptMediaType.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* limitations under the License.
*/

use Closure;
use Neomerx\JsonApi\Contracts\Http\Headers\AcceptMediaTypeInterface;
use Neomerx\JsonApi\Exceptions\InvalidArgumentException;

Expand Down Expand Up @@ -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());
Expand Down
4 changes: 2 additions & 2 deletions src/Parser/IdentifierAndResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.'
);

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/Parser/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 4 additions & 4 deletions src/Parser/RelationshipData/ParseRelationshipDataTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
{
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Parser/RelationshipData/RelationshipDataIsNull.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/Parser/RelationshipData/RelationshipDataIsResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 2 additions & 7 deletions src/Schema/ErrorCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand All @@ -52,7 +47,7 @@ public function __unserialize(array $data): void
*/
public function getIterator(): \Traversable
{
return new ArrayIterator($this->items);
return new \ArrayIterator($this->items);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/SchemaContainer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -171,7 +171,7 @@ protected function getProviderMapping(string $type)
}

/**
* @param string|Closure $schema
* @param string|\Closure $schema
*/
protected function setProviderMapping(string $type, $schema): void
{
Expand Down
3 changes: 1 addition & 2 deletions tests/BaseTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,7 +32,7 @@ abstract class BaseTestCase extends TestCase
protected function tearDown(): void
{
parent::tearDown();
Mockery::close();
\Mockery::close();
}

protected function createFactory(): FactoryInterface
Expand Down
8 changes: 2 additions & 6 deletions tests/Data/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];

Expand Down Expand Up @@ -63,6 +59,6 @@ public function offsetUnset($offset): void
*/
public function getIterator(): \Traversable
{
return new ArrayIterator($this->data);
return new \ArrayIterator($this->data);
}
}
4 changes: 1 addition & 3 deletions tests/Data/Models/Author.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
8 changes: 2 additions & 6 deletions tests/Data/Models/AuthorCModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions tests/Data/Models/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 1 addition & 3 deletions tests/Data/Models/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 1 addition & 3 deletions tests/Data/Models/Site.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
7 changes: 3 additions & 4 deletions tests/Data/Schemas/DevSchema.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
* limitations under the License.
*/

use Closure;
use Neomerx\JsonApi\Contracts\Schema\LinkInterface;
use Neomerx\JsonApi\Schema\BaseSchema;

Expand All @@ -36,7 +35,7 @@ abstract class DevSchema extends BaseSchema
private array $relationshipToRemove = [];

/**
* @var Closure
* @var \Closure
*/
private $resourceLinksClosure = null;

Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions tests/Encoder/EncodeSimpleObjectsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -94,7 +93,7 @@ public function test_encode_empty_iterator(): void
]
);

$actual = $encoder->encodeData(new ArrayIterator([]));
$actual = $encoder->encodeData(new \ArrayIterator([]));

$expected = <<<EOL
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Encoder/EncodeSparseAndFieldSetsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public function test_include_and_sparse_field_sets(): void
public function test_meta_not_loaded_in_lazy_relationships(): void
{
$throwExClosure = function () {
throw new Exception();
throw new \Exception();
};

$actual = Encoder::instance(
Expand Down
Loading

0 comments on commit 207c903

Please sign in to comment.