Skip to content

Commit

Permalink
php-cs-fixer (#22)
Browse files Browse the repository at this point in the history
* php-cs-fixer

* Remove php-cs-fixer cache file; add it to the gitignore

Co-authored-by: drtheuns <[email protected]>
  • Loading branch information
Nizari and drtheuns authored Mar 2, 2020
1 parent 118d10d commit 0685ce6
Show file tree
Hide file tree
Showing 18 changed files with 75 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ Homestead.yaml
Homestead.json
/.vagrant
.phpunit.result.cache
coverage/
coverage/
.php_cs.cache
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
}
},
"scripts": {
"fix": "php-cs-fixer fix ./src && php-cs-fixer fix ./tests",
"test": "./vendor/bin/phpunit",
"coverage": "./vendor/bin/phpunit --coverage-html coverage",
"analyse": "./vendor/bin/phpstan analyse"
Expand Down
3 changes: 1 addition & 2 deletions src/Apitizer/ExceptionStrategy/Ignore.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class Ignore implements Strategy
public function handle(
QueryBuilder $queryBuilder,
ApitizerException $apitizerException
): void
{
): void {
//
}
}
3 changes: 1 addition & 2 deletions src/Apitizer/ExceptionStrategy/Raise.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ class Raise implements Strategy
public function handle(
QueryBuilder $queryBuilder,
ApitizerException $apitizerException
): void
{
): void {
throw $apitizerException;
}
}
16 changes: 8 additions & 8 deletions src/Apitizer/Exceptions/DefinitionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __construct(
* @param string $key
* @param mixed $given
*/
static function builderClassExpected(QueryBuilder $queryBuilder, string $key, $given): self
public static function builderClassExpected(QueryBuilder $queryBuilder, string $key, $given): self
{
$class = get_class($queryBuilder);
$message = "Expected association by [$key] on [$class] to be a "
Expand All @@ -56,7 +56,7 @@ static function builderClassExpected(QueryBuilder $queryBuilder, string $key, $g
return new static($message, $queryBuilder, 'association');
}

static function associationDoesNotExist(QueryBuilder $queryBuilder, Association $associaton): self
public static function associationDoesNotExist(QueryBuilder $queryBuilder, Association $associaton): self
{
$name = $associaton->getName();
$class = get_class($queryBuilder);
Expand All @@ -74,7 +74,7 @@ static function associationDoesNotExist(QueryBuilder $queryBuilder, Association
* @param string $name
* @param mixed $given
*/
static function fieldDefinitionExpected(QueryBuilder $queryBuilder, string $name, $given): self
public static function fieldDefinitionExpected(QueryBuilder $queryBuilder, string $name, $given): self
{
$class = get_class($queryBuilder);
$type = is_object($given) ? get_class($given) : gettype($given);
Expand All @@ -89,7 +89,7 @@ static function fieldDefinitionExpected(QueryBuilder $queryBuilder, string $name
* @param string $name
* @param mixed $given
*/
static function associationDefinitionExpected(
public static function associationDefinitionExpected(
QueryBuilder $queryBuilder,
string $name,
$given
Expand All @@ -107,7 +107,7 @@ static function associationDefinitionExpected(
* @param string $name
* @param mixed $given
*/
static function filterDefinitionExpected(QueryBuilder $queryBuilder, string $name, $given): self
public static function filterDefinitionExpected(QueryBuilder $queryBuilder, string $name, $given): self
{
$class = get_class($queryBuilder);
$type = is_object($given) ? get_class($given) : gettype($given);
Expand All @@ -117,7 +117,7 @@ static function filterDefinitionExpected(QueryBuilder $queryBuilder, string $nam
return new static($message, $queryBuilder, 'filter', $name);
}

static function filterHandlerNotDefined(QueryBuilder $queryBuilder, Filter $filter): self
public static function filterHandlerNotDefined(QueryBuilder $queryBuilder, Filter $filter): self
{
$class = get_class($queryBuilder);
$name = $filter->getName();
Expand All @@ -131,7 +131,7 @@ static function filterHandlerNotDefined(QueryBuilder $queryBuilder, Filter $filt
* @param string $name
* @param mixed $given
*/
static function sortDefinitionExpected(QueryBuilder $queryBuilder, string $name, $given): self
public static function sortDefinitionExpected(QueryBuilder $queryBuilder, string $name, $given): self
{
$class = get_class($queryBuilder);
$type = is_object($given) ? get_class($given) : gettype($given);
Expand All @@ -141,7 +141,7 @@ static function sortDefinitionExpected(QueryBuilder $queryBuilder, string $name,
return new static($message, $queryBuilder, 'sort', $name);
}

static function sortHandlerNotDefined(QueryBuilder $queryBuilder, string $name): self
public static function sortHandlerNotDefined(QueryBuilder $queryBuilder, string $name): self
{
$class = get_class($queryBuilder);
$message = "Expected a callable handler to be defined for sort [$name] on [$class]";
Expand Down
3 changes: 2 additions & 1 deletion src/Apitizer/Parser/Context.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ class Context
/**
* @param Relation|ParsedInput $stack
*/
public function __construct($stack, Context $parent = null) {
public function __construct($stack, Context $parent = null)
{
$this->stack = $stack;
$this->parent = $parent;
}
Expand Down
13 changes: 9 additions & 4 deletions src/Apitizer/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,8 @@ public function afterQuery(Builder $query, FetchSpec $fetchSpec): Builder
return $query;
}

public function __construct(Request $request = null) {
public function __construct(Request $request = null)
{
$this->setRequest($request);
}

Expand Down Expand Up @@ -382,7 +383,9 @@ public function paginate(int $perPage = null, $pageName = 'page', $page = null):

return tap($paginator, function (AbstractPaginator $paginator) use ($fetchSpec) {
$renderedData = $this->getRenderer()->render(
$this, $paginator->getCollection(), $fetchSpec
$this,
$paginator->getCollection(),
$fetchSpec
);

$paginator->setCollection(collect($renderedData));
Expand Down Expand Up @@ -474,7 +477,8 @@ protected function makeFetchSpecification(): FetchSpec
: RawInput::fromArray($this->specification);

return FetchSpecFactory::fromRequestInput(
$this->getParser()->parse($rawInput), $this
$this->getParser()->parse($rawInput),
$this
);
}

Expand All @@ -497,7 +501,8 @@ public function getAssociations(): array
{
if (is_null($this->availableAssociations)) {
$this->availableAssociations = DefinitionHelper::validateAssociations(
$this, $this->associations()
$this,
$this->associations()
);
}

Expand Down
11 changes: 7 additions & 4 deletions src/Apitizer/Rendering/BasicRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ class BasicRenderer extends AbstractRenderer implements Renderer
public function render(QueryBuilder $queryBuilder, $data, FetchSpec $fetchSpec): array
{
return $this->doRender(
$queryBuilder, $data,
$queryBuilder,
$data,
$fetchSpec->getFields(),
$fetchSpec->getAssociations()
);
Expand Down Expand Up @@ -120,16 +121,18 @@ protected function addRenderedAssociation(
$row,
Association $association,
array &$renderedData
): void{
): void {
$associationData = $this->valueFromRow($row, $association->getKey());

if (! $association->passesPolicy($associationData, $row)) {
return;
}

$renderedData[$association->getName()] = $this->doRender(
$association->getRelatedQueryBuilder(), $associationData,
$association->getFields() ?? [], $association->getAssociations() ?? []
$association->getRelatedQueryBuilder(),
$associationData,
$association->getFields() ?? [],
$association->getAssociations() ?? []
);
}
}
23 changes: 12 additions & 11 deletions src/Apitizer/Support/DefinitionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DefinitionHelper
*
* @return array<string, AbstractField>
*/
static function validateFields(QueryBuilder $queryBuilder, array $fields): array
public static function validateFields(QueryBuilder $queryBuilder, array $fields): array
{
$castFields = [];

Expand All @@ -44,7 +44,7 @@ static function validateFields(QueryBuilder $queryBuilder, array $fields): array
*
* @return AbstractField
*/
static function validateField(QueryBuilder $queryBuilder, string $name, $field)
public static function validateField(QueryBuilder $queryBuilder, string $name, $field)
{
if (is_string($field)) {
$field = new Field($queryBuilder, $field, 'any');
Expand All @@ -65,7 +65,7 @@ static function validateField(QueryBuilder $queryBuilder, string $name, $field)
*
* @return array<string, Association>
*/
static function validateAssociations(QueryBuilder $queryBuilder, array $associations): array
public static function validateAssociations(QueryBuilder $queryBuilder, array $associations): array
{
$castFields = [];

Expand All @@ -81,14 +81,16 @@ static function validateAssociations(QueryBuilder $queryBuilder, array $associat
* @param string $name
* @param Association|mixed $association
*/
static function validateAssociation(
public static function validateAssociation(
QueryBuilder $queryBuilder,
string $name,
$association
): Association {
if (! $association instanceof Association) {
throw DefinitionException::associationDefinitionExpected(
$queryBuilder, $name, $association
$queryBuilder,
$name,
$association
);
}

Expand All @@ -104,8 +106,7 @@ static function validateAssociation(
private static function isValidAssociation(
QueryBuilder $queryBuilder,
Association $association
): bool
{
): bool {
$key = $association->getKey();
$model = $queryBuilder->model();

Expand All @@ -120,7 +121,7 @@ private static function isValidAssociation(
*
* @return array<string, Sort>
*/
static function validateSorts(QueryBuilder $queryBuilder, array $sorts): array
public static function validateSorts(QueryBuilder $queryBuilder, array $sorts): array
{
foreach ($sorts as $name => $sort) {
static::validateSort($queryBuilder, $name, $sort);
Expand All @@ -134,7 +135,7 @@ static function validateSorts(QueryBuilder $queryBuilder, array $sorts): array
* @param string $name
* @param Sort|mixed $sort
*/
static function validateSort(QueryBuilder $queryBuilder, string $name, $sort): void
public static function validateSort(QueryBuilder $queryBuilder, string $name, $sort): void
{
if (! $sort instanceof Sort) {
throw DefinitionException::sortDefinitionExpected($queryBuilder, $name, $sort);
Expand All @@ -155,7 +156,7 @@ static function validateSort(QueryBuilder $queryBuilder, string $name, $sort): v
*
* @return array<string, Filter>
*/
static function validateFilters(QueryBuilder $queryBuilder, array $filters): array
public static function validateFilters(QueryBuilder $queryBuilder, array $filters): array
{
foreach ($filters as $name => $filter) {
static::validateFilter($queryBuilder, $name, $filter);
Expand All @@ -171,7 +172,7 @@ static function validateFilters(QueryBuilder $queryBuilder, array $filters): arr
*
* @throws DefinitionException
*/
static function validateFilter(QueryBuilder $queryBuilder, string $name, $filter): void
public static function validateFilter(QueryBuilder $queryBuilder, string $name, $filter): void
{
if (! $filter instanceof Filter) {
throw DefinitionException::filterDefinitionExpected($queryBuilder, $name, $filter);
Expand Down
11 changes: 8 additions & 3 deletions src/Apitizer/Support/FetchSpecFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public function make(): FetchSpec
{
$fields = $this->selectedFields($this->queryBuilder, $this->input->fields);
$associations = $this->selectedAssociations(
$this->queryBuilder, $this->input->associations, $this->input->fields
$this->queryBuilder,
$this->input->associations,
$this->input->fields
);

// If nothing was (correct) was selected, return all the default fields
Expand Down Expand Up @@ -107,7 +109,9 @@ protected function selectedAssociations(
);
$association->setAssociations(
$this->selectedAssociations(
$relatedBuilder, $relation->associations, $relation->fields
$relatedBuilder,
$relation->associations,
$relation->fields
)
);

Expand Down Expand Up @@ -168,7 +172,8 @@ protected function selectedFilters(): array
}
} catch (InvalidInputException $e) {
$this->queryBuilder->getExceptionStrategy()->handle(
$this->queryBuilder, $e
$this->queryBuilder,
$e
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Apitizer/Types/Concerns/FetchesValueFromRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ protected function valueFromRow($row, string $key)

if ($row instanceof ArrayAccess || is_array($row)) {
$value = $row[$key];
} else if (is_object($row)) {
} elseif (is_object($row)) {
$value = $row->{$key};
}

Expand Down
3 changes: 2 additions & 1 deletion src/Apitizer/Validation/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public function hasRulesFor(string $actionMethod): bool
protected function resolveRulesFor(string $actionMethod): ObjectRules
{
if (! $this->hasRulesFor($actionMethod)) {
return new ObjectRules(null, function () {});
return new ObjectRules(null, function () {
});
}

$object = $this->rules[$actionMethod];
Expand Down
4 changes: 3 additions & 1 deletion tests/Feature/Commands/ValidateSchemaCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ public function it_should_list_any_unexpected_exceptions_that_occurred()
}
}

class NotABuilder{}
class NotABuilder
{
}
class AssociationDoesNotExist extends EmptyBuilder
{
public function associations(): array
Expand Down
3 changes: 2 additions & 1 deletion tests/Feature/QueryBuilder/PaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public function pagination_links_contain_all_supported_query_parameters()
$this->paginatorLinkContainsString($paginator, 'limit=1');
}

private function paginatorLinkContainsString(LengthAwarePaginator $paginator, string $string) {
private function paginatorLinkContainsString(LengthAwarePaginator $paginator, string $string)
{
$this->assertStringContainsStringIgnoringCase($string, urldecode($paginator->nextPageUrl()));
$this->assertStringContainsStringIgnoringCase($string, urldecode($paginator->url(1)));
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/QueryBuilder/SelectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class SelectTest extends TestCase
{
/** @test */
/** @test */
public function it_can_select_the_specified_fields()
{
$post = factory(Post::class)->create();
Expand Down
4 changes: 3 additions & 1 deletion tests/Feature/Support/SchemaValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ private function assertHasErrors(QueryBuilder $queryBuilder, $count = 1)
}
}

class NotABuilder {}
class NotABuilder
{
}
class BuilderClassExpected extends EmptyBuilder
{
public function fields(): array
Expand Down
8 changes: 6 additions & 2 deletions tests/Unit/Types/ApidocTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,9 @@ public function arbitrary_metadata_can_be_attached_to_the_documenation()
}

// Used as examples for name guessing.
class UserQueryBuilder extends EmptyBuilder {}
class NonBuilderName extends EmptyBuilder {}
class UserQueryBuilder extends EmptyBuilder
{
}
class NonBuilderName extends EmptyBuilder
{
}
Loading

0 comments on commit 0685ce6

Please sign in to comment.