Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ jobs:
run: composer install --prefer-dist --no-progress

- name: Run CS
run: vendor/bin/phpcs -p --extensions=php ./src ./tests
run: vendor/bin/phpcs

- name: Run stan
run: vendor/bin/phpstan analyse ./src --level 4
run: vendor/bin/phpstan analyse

- name: Run tests
run: vendor/bin/phpunit --coverage-clover=coverage.xml
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
/nbproject
/phpunit.xml
/coverage.xml
.phpunit.*
44 changes: 0 additions & 44 deletions .travis.yml

This file was deleted.

15 changes: 10 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"type": "cakephp-plugin",
"license": "MIT",
"require": {
"php": ">=5.6",
"cakephp/orm": "^3.4"
"cakephp/orm": "~4.0"
},
"require-dev": {
"cakephp/cakephp": "~3.4.0",
"cakephp/cakephp-codesniffer": "^3.0",
"phpunit/phpunit": "^5.6|^6"
"cakephp/cakephp": "~4.0",
"cakephp/cakephp-codesniffer": "^4.0",
"phpunit/phpunit": "^9.5",
"phpstan/phpstan": "^2.0"
},
"autoload": {
"psr-4": {
Expand All @@ -23,5 +23,10 @@
"Cake\\Test\\": "vendor/cakephp/cakephp/tests",
"Robotusers\\Chunk\\Test\\": "tests"
}
},
"config": {
"allow-plugins": {
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
16 changes: 14 additions & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
<?xml version="1.0"?>
<ruleset name="CakePHP Core">
<rule ref="./vendor/cakephp/cakephp-codesniffer/CakePHP/ruleset.xml"/>
<ruleset name="Robotusers">
<rule ref="CakePHP">
<exclude name="CakePHP.Commenting.FunctionComment.Missing"/>
<exclude name="CakePHP.Commenting.FunctionComment.MissingParamComment"/>
<exclude name="CakePHP.Commenting.FunctionComment.MissingParamTag"/>
<exclude name="CakePHP.NamingConventions.ValidTraitName"/>
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
<exclude name="Generic.Files.LineLength"/>
</rule>
<file>src/</file>
<file>tests/</file>
</ruleset>
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
parameters:
level: 4
# reportUnmatchedIgnoredErrors: false
# treatPhpDocTypesAsCertain: false
paths:
- src/
- tests/
7 changes: 4 additions & 3 deletions src/Model/Behavior/ChunkBehavior.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/*
* The MIT License
*
Expand Down Expand Up @@ -30,13 +32,12 @@

class ChunkBehavior extends Behavior
{

/**
* Returns chunked result set.
*
* @param Query $query Query instance.
* @param \Cake\ORM\Query $query Query instance.
* @param array $config Config.
* @return ResultSet
* @return \Robotusers\Chunk\ORM\ResultSet
*/
public function chunk(Query $query, array $config = [])
{
Expand Down
50 changes: 32 additions & 18 deletions src/ORM/ResultSet.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/*
* The MIT License
*
Expand Down Expand Up @@ -45,7 +47,7 @@ class ResultSet implements ResultSetInterface
/**
* Query instance.
*
* @var Query
* @var \Cake\ORM\Query
*/
protected $query;

Expand Down Expand Up @@ -113,15 +115,15 @@ class ResultSet implements ResultSetInterface
* @var array
*/
protected $_defaultConfig = [
'size' => 1000
'size' => 1000,
];

/**
* Constructor.
*
* @param Query $query Query object.
* @param \Cake\ORM\Query $query Query object.
* @param array $config Configuration.
* @throws RuntimeException When query is not supported.
* @throws \RuntimeException When query is not supported.
*/
public function __construct(Query $query, array $config = [])
{
Expand All @@ -140,34 +142,36 @@ public function __construct(Query $query, array $config = [])
}

/**
* {@inheritDoc}
* @inheritDoc
*/
#[\ReturnTypeWillChange]
public function current()
{
return $this->current;
}

/**
* {@inheritDoc}
* @inheritDoc
*/
#[\ReturnTypeWillChange]
public function key()
{
return $this->index;
}

/**
* {@inheritDoc}
* @inheritDoc
*/
public function next()
public function next(): void
{
$this->index++;
$this->chunkIndex++;
}

/**
* {@inheritDoc}
* @inheritDoc
*/
public function rewind()
public function rewind(): void
{
$this->index = 0;
$this->page = 1;
Expand All @@ -176,9 +180,9 @@ public function rewind()
}

/**
* {@inheritDoc}
* @inheritDoc
*/
public function valid()
public function valid(): bool
{
if ($this->limit && $this->index >= $this->limit) {
return false;
Expand Down Expand Up @@ -235,30 +239,40 @@ protected function fetchChunk()
}

/**
* {@inheritDoc}
* @inheritDoc
*/
public function count()
public function count(): int
{
throw new RuntimeException('Count is not supported yet.');
}

/**
* Serialization is not supported (yet).
*
* {@inheritDoc}
*
* Serialization is not supported (yet). *
*/
public function serialize()
{
throw new RuntimeException('You cannot serialize this result set.');
}

public function __serialize(): array
{
throw new RuntimeException('You cannot serialize this result set.');
}

/**
* Serialization is not supported (yet).
*
* {@inheritDoc}
*
* Serialization is not supported (yet). *
*/
public function unserialize($serialized)
{
throw new RuntimeException('You cannot unserialize this result set.');
}

public function __unserialize(array $data): void
{
throw new RuntimeException('You cannot unserialize this result set.');
}
}
6 changes: 4 additions & 2 deletions tests/TestCase/Model/Behavior/ChunkBehaviorTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

/*
* The MIT License
*
Expand Down Expand Up @@ -37,7 +39,7 @@
class ChunkBehaviorTest extends TestCase
{
public $fixtures = [
'core.authors'
'core.Authors',
];

public function testChunk()
Expand All @@ -47,7 +49,7 @@ public function testChunk()

$behavior = new ChunkBehavior($table);
$chunk = $behavior->chunk($query, [
'size' => 100
'size' => 100,
]);

$this->assertInstanceOf(ResultSet::class, $chunk);
Expand Down
Loading
Loading