Skip to content

Commit

Permalink
Update StyleCI config + fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Nov 20, 2020
1 parent 34a17f7 commit 60084db
Show file tree
Hide file tree
Showing 19 changed files with 152 additions and 34 deletions.
90 changes: 87 additions & 3 deletions .styleci.yml
@@ -1,6 +1,90 @@
preset: psr12
risky: true

version: 8

finder:
exclude:
- docs
- vendor
exclude:
- docs
- vendor
- resources
- views
- public
not-name:
- UnionCar.php

enabled:
- alpha_ordered_imports
- alpha_ordered_traits
- array_indentation
- array_push
- combine_consecutive_issets
- combine_consecutive_unsets
- combine_nested_dirname
- declare_strict_types
- dir_constant
- final_static_access
- fully_qualified_strict_types
- function_to_constant
- hash_to_slash_comment
- is_null
- logical_operators
- magic_constant_casing
- magic_method_casing
- method_separation
- modernize_types_casting
- native_function_casing
- native_function_type_declaration_casing
- no_alias_functions
- no_alternative_syntax
- no_empty_comment
- no_empty_phpdoc
- no_empty_statement
- no_extra_block_blank_lines
- no_short_bool_cast
- no_short_echo_tag
- no_superfluous_elseif
- no_unneeded_control_parentheses
- no_unneeded_curly_braces
- no_unneeded_final_method
- no_unset_cast
- no_unused_imports
- no_unused_lambda_imports
- no_useless_else
- no_useless_return
- normalize_index_brace
- php_unit_dedicate_assert
- php_unit_dedicate_assert_internal_type
- php_unit_expectation
- php_unit_mock
- php_unit_mock_short_will_return
- php_unit_namespaced
- php_unit_no_expectation_annotation
- phpdoc_no_empty_return
- phpdoc_no_useless_inheritdoc
- phpdoc_order
- phpdoc_property
- phpdoc_scalar
- phpdoc_separation
- phpdoc_singular_inheritdoc
- phpdoc_trim
- phpdoc_trim_consecutive_blank_line_separation
- phpdoc_type_to_var
- phpdoc_types
- phpdoc_types_order
- phpdoc_var_without_name
- print_to_echo
- regular_callable_call
- return_assignment
- self_accessor
- self_static_accessor
- set_type_to_cast
- short_array_syntax
- short_list_syntax
- simplified_if_return
- single_quote
- standardize_not_equals
- ternary_to_null_coalescing
- trailing_comma_in_multiline_array
- unalign_double_arrow
- unalign_equals
4 changes: 2 additions & 2 deletions src/Paginator/OffsetPaginator.php
Expand Up @@ -16,7 +16,7 @@
*/
final class OffsetPaginator implements PaginatorInterface
{
/** @var OffsetableDataInterface|ReadableDataInterface|CountableDataInterface */
/** @var CountableDataInterface|OffsetableDataInterface|ReadableDataInterface */
private ReadableDataInterface $dataReader;
private int $currentPage = 1;
private int $pageSize = self::DEFAULT_PAGE_SIZE;
Expand Down Expand Up @@ -128,7 +128,7 @@ public function read(): iterable
if ($this->currentPage > $this->getInternalTotalPages()) {
throw new PaginatorException('Page not found');
}
/** @var OffsetableDataInterface|ReadableDataInterface|CountableDataInterface $reader */
/** @var CountableDataInterface|OffsetableDataInterface|ReadableDataInterface $reader */
$this->cachedReader = $this->dataReader->withLimit($this->pageSize)->withOffset($this->getOffset());
yield from $this->cachedReader->read();
}
Expand Down
10 changes: 10 additions & 0 deletions src/Paginator/PaginatorInterface.php
Expand Up @@ -16,32 +16,42 @@ interface PaginatorInterface
* @psalm-return iterable<TKey, TValue>
*/
public function read(): iterable;

/**
* Check that Paginator has more than one page
*/
public function isRequired(): bool;

public function isOnLastPage(): bool;

public function isOnFirstPage(): bool;

public function getNextPageToken(): ?string;

public function getPreviousPageToken(): ?string;

/**
* @return $this
*
* @psalm-mutation-free
*/
public function withNextPageToken(?string $token): self;

/**
* @return $this
*
* @psalm-mutation-free
*/
public function withPreviousPageToken(?string $token): self;

/**
* @return $this
*
* @psalm-mutation-free
*/
public function withPageSize(int $limit): self;

public function getPageSize(): int;

public function getCurrentPageSize(): int;
}
1 change: 1 addition & 0 deletions src/Reader/Filter/FilterInterface.php
Expand Up @@ -7,5 +7,6 @@
interface FilterInterface
{
public static function getOperator(): string;

public function toArray(): array;
}
1 change: 1 addition & 0 deletions src/Reader/Filter/GroupFilter.php
Expand Up @@ -44,6 +44,7 @@ public function toArray(): array
* ~~~
*
* @param array $filtersArray
*
* @return $this
*/
public function withFiltersArray(array $filtersArray)
Expand Down
1 change: 0 additions & 1 deletion src/Reader/Filter/Like.php
Expand Up @@ -15,7 +15,6 @@ public function __construct(string $field, string $value)
$this->value = $value;
}


public function toArray(): array
{
return [self::getOperator(), $this->field, $this->value];
Expand Down
3 changes: 3 additions & 0 deletions src/Reader/FilterableDataInterface.php
Expand Up @@ -11,13 +11,16 @@ interface FilterableDataInterface
{
/**
* @param FilterInterface $filter
*
* @return $this
*
* @psalm-mutation-free
*/
public function withFilter(FilterInterface $filter): self;

/**
* @param FilterProcessorInterface[] $filterProcessors
*
* @return $this
*
* @psalm-mutation-free
Expand Down
6 changes: 4 additions & 2 deletions src/Reader/Iterable/IterableDataReader.php
Expand Up @@ -9,18 +9,18 @@
use Yiisoft\Arrays\ArraySorter;
use Yiisoft\Data\Reader\DataReaderInterface;
use Yiisoft\Data\Reader\Filter\FilterInterface;
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
use Yiisoft\Data\Reader\Iterable\Processor\All;
use Yiisoft\Data\Reader\Iterable\Processor\Any;
use Yiisoft\Data\Reader\Iterable\Processor\Equals;
use Yiisoft\Data\Reader\Iterable\Processor\GreaterThan;
use Yiisoft\Data\Reader\Iterable\Processor\GreaterThanOrEqual;
use Yiisoft\Data\Reader\Iterable\Processor\In;
use Yiisoft\Data\Reader\Iterable\Processor\IterableProcessorInterface;
use Yiisoft\Data\Reader\Iterable\Processor\LessThan;
use Yiisoft\Data\Reader\Iterable\Processor\LessThanOrEqual;
use Yiisoft\Data\Reader\Iterable\Processor\Like;
use Yiisoft\Data\Reader\Iterable\Processor\Not;
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
use Yiisoft\Data\Reader\Iterable\Processor\IterableProcessorInterface;
use Yiisoft\Data\Reader\Sort;

/**
Expand Down Expand Up @@ -79,8 +79,10 @@ public function getSort(): ?Sort

/**
* Sorts data items according to the given sort definition.
*
* @param iterable $items the items to be sorted
* @param Sort $sort the sort definition
*
* @return iterable the sorted items
*/
private function sortItems(iterable $items, Sort $sort): iterable
Expand Down
1 change: 1 addition & 0 deletions src/Reader/OffsetableDataInterface.php
Expand Up @@ -8,6 +8,7 @@ interface OffsetableDataInterface
{
/**
* @param int $offset
*
* @return $this
*
* @psalm-mutation-free
Expand Down
6 changes: 5 additions & 1 deletion src/Reader/ReadableDataInterface.php
Expand Up @@ -14,16 +14,20 @@ interface ReadableDataInterface
{
/**
* @param int $limit A limit of 0 means "no limit".
* @return $this
*
* @throws InvalidArgumentException if limit less than 0.
*
* @return $this
*
* @psalm-mutation-free
*/
public function withLimit(int $limit): self;

/**
* @psalm-return iterable<TKey, TValue>
*/
public function read(): iterable;

/**
* @psalm-return TValue
*/
Expand Down
2 changes: 2 additions & 0 deletions src/Reader/Sort.php
Expand Up @@ -81,6 +81,7 @@ public function __construct(array $config)
* or the field name prefixed with `-` for descending.
*
* @param string $orderString
*
* @return $this
*/
public function withOrderString(string $orderString): self
Expand All @@ -99,6 +100,7 @@ public function withOrderString(string $orderString): self

/**
* @param array $order field names to order by as keys, direction as values
*
* @return $this
*/
public function withOrder(array $order): self
Expand Down
1 change: 1 addition & 0 deletions src/Reader/SortableDataInterface.php
Expand Up @@ -8,6 +8,7 @@ interface SortableDataInterface
{
/**
* @param Sort|null $sorting
*
* @return $this
*
* @psalm-mutation-free
Expand Down
13 changes: 7 additions & 6 deletions tests/Paginator/KeysetPaginatorTest.php
Expand Up @@ -5,10 +5,10 @@
namespace Yiisoft\Data\Tests\Paginator;

use Yiisoft\Data\Paginator\KeysetPaginator;
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
use Yiisoft\Data\Reader\Iterable\IterableDataReader;
use Yiisoft\Data\Reader\Filter\FilterInterface;
use Yiisoft\Data\Reader\Filter\FilterProcessorInterface;
use Yiisoft\Data\Reader\FilterableDataInterface;
use Yiisoft\Data\Reader\Iterable\IterableDataReader;
use Yiisoft\Data\Reader\ReadableDataInterface;
use Yiisoft\Data\Reader\Sort;
use Yiisoft\Data\Reader\SortableDataInterface;
Expand Down Expand Up @@ -113,6 +113,7 @@ public function onePageDataProvider(): array
[$this->getDataSet([0, 1, 2, 3]), 4],
];
}

/**
* @dataProvider onePageDataProvider
*/
Expand Down Expand Up @@ -167,7 +168,7 @@ public function testReadObjectsWithPublicProperties(): void
$data = [
$this->createObjectWithPublicProperties(1, 'Codename Boris 1'),
$this->createObjectWithPublicProperties(2, 'Codename Boris 2'),
$this->createObjectWithPublicProperties(3, 'Codename Boris 3')
$this->createObjectWithPublicProperties(3, 'Codename Boris 3'),
];

$dataReader = (new IterableDataReader($data))->withSort($sort);
Expand All @@ -185,7 +186,7 @@ public function testReadObjectsWithGetters(): void
$data = [
$this->createObjectWithGetters(1, 'Codename Boris 1'),
$this->createObjectWithGetters(2, 'Codename Boris 2'),
$this->createObjectWithGetters(3, 'Codename Boris 3')
$this->createObjectWithGetters(3, 'Codename Boris 3'),
];

$dataReader = $this->createObjectDataReader($data)->withSort($sort);
Expand All @@ -206,7 +207,7 @@ public function testReadSecondPage(): void

$paginator = (new KeysetPaginator($dataReader))
->withPageSize(2)
->withNextPageToken("2");
->withNextPageToken('2');

$expected = $this->getDataSet([2, 3]);

Expand Down Expand Up @@ -263,7 +264,7 @@ public function testForwardAndBackwardPagination(): void

$paginator = (new KeysetPaginator($dataReader))
->withPageSize(2)
->withNextPageToken("2");
->withNextPageToken('2');

$expected = $this->getDataSet([2, 3]);
$read = array_values($this->iterableToArray($paginator->read()));
Expand Down
6 changes: 6 additions & 0 deletions tests/Paginator/OffsetPaginatorTest.php
Expand Up @@ -52,10 +52,12 @@ public function read(): iterable
{
return [];
}

public function readOne()
{
return null;
}

public function count(): int
{
return 0;
Expand All @@ -80,18 +82,22 @@ public function withLimit(int $limit): self
{
// do nothing
}

public function read(): iterable
{
return [];
}

public function readOne()
{
return null;
}

public function count(): int
{
return 0;
}

public function withOffset(int $offset): self
{
// do nothing
Expand Down

0 comments on commit 60084db

Please sign in to comment.