Skip to content

Commit

Permalink
Fix examples code style
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Dec 30, 2019
1 parent 97c6da4 commit 66ec0e6
Show file tree
Hide file tree
Showing 31 changed files with 64 additions and 33 deletions.
1 change: 1 addition & 0 deletions examples/Book/Action/CreateBookAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\Action;
Expand Down
1 change: 1 addition & 0 deletions examples/Book/Action/GetAuthorsOfBookAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\Action;
Expand Down
1 change: 1 addition & 0 deletions examples/Book/Action/GetBookAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\Action;
Expand Down
1 change: 1 addition & 0 deletions examples/Book/Action/GetBookRelationshipsAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\Action;
Expand Down
1 change: 1 addition & 0 deletions examples/Book/Action/GetBooksAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\Action;
Expand Down
1 change: 1 addition & 0 deletions examples/Book/Action/UpdateBookAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\Action;
Expand Down
1 change: 1 addition & 0 deletions examples/Book/Action/UpdateBookRelationshipAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\Action;
Expand Down
1 change: 1 addition & 0 deletions examples/Book/JsonApi/Document/AuthorsDocument.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\JsonApi\Document;
Expand Down
1 change: 1 addition & 0 deletions examples/Book/JsonApi/Document/BookDocument.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\JsonApi\Document;
Expand Down
1 change: 1 addition & 0 deletions examples/Book/JsonApi/Document/BooksDocument.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\JsonApi\Document;
Expand Down
5 changes: 3 additions & 2 deletions examples/Book/JsonApi/Hydrator/BookHydator.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\JsonApi\Hydrator;
Expand Down Expand Up @@ -116,7 +117,7 @@ protected function getAttributeHydrator($book): array
},
"pages" => function (array &$book, $attribute, $data) {
$book["pages"] = $attribute;
}
},
];
}

Expand Down Expand Up @@ -154,7 +155,7 @@ protected function getRelationshipHydrator($book): array
} else {
$book["publisher"] = BookRepository::getPublisher((int) $publisher->getResourceIdentifier()->getId());
}
}
},
];
}
}
7 changes: 4 additions & 3 deletions examples/Book/JsonApi/Resource/AuthorResource.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\JsonApi\Resource;
Expand All @@ -20,7 +21,7 @@ class AuthorResource extends AbstractResource
*
* @param array $author
*/
public function getType($author) : string
public function getType($author): string
{
return "authors";
}
Expand All @@ -32,7 +33,7 @@ public function getType($author) : string
*
* @param array $author
*/
public function getId($author) : string
public function getId($author): string
{
return (string) $this->object["id"];
}
Expand All @@ -45,7 +46,7 @@ public function getId($author) : string
*
* @param array $author
*/
public function getMeta($author) : array
public function getMeta($author): array
{
return [];
}
Expand Down
15 changes: 6 additions & 9 deletions examples/Book/JsonApi/Resource/BookResource.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\JsonApi\Resource;
Expand Down Expand Up @@ -142,26 +143,22 @@ public function getRelationships($book): array
{
return [
"authors" => function (array $book) {
return
ToManyRelationship::create()
return ToManyRelationship::create()
->setLinks(
new RelationshipLinks($this->getSelfLinkHref($book), new Link("/relationships/authors"))
)
->setData($book["authors"], $this->authorTransformer)
;
->setData($book["authors"], $this->authorTransformer);
},
"publisher" => function ($book) {
return
ToOneRelationship::create()
return ToOneRelationship::create()
->setLinks(
RelationshipLinks::createWithoutBaseUri()
->setBaseUri($this->getSelfLinkHref($book))
->setSelf(new Link("/relationships/publisher"))
)
->setData($book["publisher"], $this->publisherTransformer)
->omitDataWhenNotIncluded()
;
}
->omitDataWhenNotIncluded();
},
];
}
}
9 changes: 4 additions & 5 deletions examples/Book/JsonApi/Resource/PublisherResource.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\JsonApi\Resource;
Expand Down Expand Up @@ -112,11 +113,9 @@ public function getRelationships($publisher): array
{
return [
"representative" => function ($publisher) {
return
ToOneRelationship::create()
->setData($publisher["representative"], $this->representativeTransformer)
;
}
return ToOneRelationship::create()
->setData($publisher["representative"], $this->representativeTransformer);
},
];
}
}
1 change: 1 addition & 0 deletions examples/Book/JsonApi/Resource/RepresentativeResource.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\JsonApi\Resource;
Expand Down
6 changes: 5 additions & 1 deletion examples/Book/Repository/BookRepository.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Book\Repository;

use WoohooLabs\Yin\Examples\Utils\AbstractRepository;
use WoohooLabs\Yin\Examples\Utils\Collection;

use function array_slice;
use function count;

class BookRepository extends AbstractRepository
{
/**
Expand Down Expand Up @@ -103,7 +107,7 @@ class BookRepository extends AbstractRepository
],
];

public static function getBooks(int $page = null, int $size = null): Collection
public static function getBooks(?int $page = null, ?int $size = null): Collection
{
if ($page === null) {
$page = 1;
Expand Down
1 change: 1 addition & 0 deletions examples/User/Action/GetUserAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\User\Action;
Expand Down
1 change: 1 addition & 0 deletions examples/User/Action/GetUserRelationshipsAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\User\Action;
Expand Down
1 change: 1 addition & 0 deletions examples/User/Action/GetUsersAction.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\User\Action;
Expand Down
1 change: 1 addition & 0 deletions examples/User/JsonApi/Document/UserDocument.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\User\JsonApi\Document;
Expand Down
1 change: 1 addition & 0 deletions examples/User/JsonApi/Document/UsersDocument.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\User\JsonApi\Document;
Expand Down
1 change: 1 addition & 0 deletions examples/User/JsonApi/Resource/ContactResource.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\User\JsonApi\Resource;
Expand Down
9 changes: 4 additions & 5 deletions examples/User/JsonApi/Resource/UserResource.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\User\JsonApi\Resource;
Expand Down Expand Up @@ -117,8 +118,7 @@ public function getRelationships($user): array
{
return [
"contacts" => function (array $user) {
return
ToManyRelationship::create()
return ToManyRelationship::create()
->setLinks(
RelationshipLinks::createWithoutBaseUri(
new Link("/users/" . $user["id"] . "/contacts"),
Expand All @@ -128,9 +128,8 @@ public function getRelationships($user): array
->setDataAsCallable(function () use ($user) {
return $user["contacts"];
}, $this->contactTransformer)
->omitDataWhenNotIncluded()
;
}
->omitDataWhenNotIncluded();
},
];
}
}
6 changes: 5 additions & 1 deletion examples/User/Repository/UserRepository.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\User\Repository;

use WoohooLabs\Yin\Examples\Utils\Collection;

use function array_slice;
use function count;

class UserRepository
{
/**
Expand Down Expand Up @@ -47,7 +51,7 @@ class UserRepository
],
];

public static function getUsers(int $page = null, int $size = null): Collection
public static function getUsers(?int $page = null, ?int $size = null): Collection
{
if ($page === null) {
$page = 1;
Expand Down
1 change: 1 addition & 0 deletions examples/Utils/AbstractRepository.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Utils;
Expand Down
1 change: 1 addition & 0 deletions examples/Utils/Collection.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Utils;
Expand Down
1 change: 1 addition & 0 deletions examples/Utils/ExampleExceptionFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Utils;
Expand Down
3 changes: 2 additions & 1 deletion examples/Utils/ExampleResourceNotFound.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Utils;
Expand Down Expand Up @@ -28,7 +29,7 @@ protected function getErrors(): array
->setStatus("404")
->setCode("RESOURCE_NOT_FOUND")
->setTitle("Resource not found")
->setDetail($this->getMessage())
->setDetail($this->getMessage()),
];
}
}
15 changes: 9 additions & 6 deletions examples/Utils/Uuid.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,34 @@
<?php

declare(strict_types=1);

namespace WoohooLabs\Yin\Examples\Utils;

use function random_int;
use function sprintf;

class Uuid
{
public static function generate(): string
{
return sprintf(
'%04x%04x-%04x-%04x-%04x-%04x%04x%04x',
// 32 bits for "time_low"
random_int(0, 0xffff), random_int(0, 0xffff),

random_int(0, 0xffff),
random_int(0, 0xffff),
// 16 bits for "time_mid"
random_int(0, 0xffff),

// 16 bits for "time_hi_and_version",
// four most significant bits holds version number 4
random_int(0, 0x0fff) | 0x4000,

// 16 bits, 8 bits for "clk_seq_hi_res",
// 8 bits for "clk_seq_low",
// two most significant bits holds zero and one for variant DCE1.1
random_int(0, 0x3fff) | 0x8000,

// 48 bits for "node"
random_int(0, 0xffff), random_int(0, 0xffff), random_int(0, 0xffff)
random_int(0, 0xffff),
random_int(0, 0xffff),
random_int(0, 0xffff)
);
}
}
1 change: 1 addition & 0 deletions examples/index.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

require_once "../vendor/autoload.php";
Expand Down
1 change: 1 addition & 0 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
<!-- Show progress of the run -->
<arg value="nps"/>

<file>examples/</file>
<file>src/</file>
<file>tests/</file>

Expand Down

0 comments on commit 66ec0e6

Please sign in to comment.