Skip to content

Commit e85924d

Browse files
Merge pull request #3 from robotusers/0.2
Update to Cake 4
2 parents 9fe19c2 + 091e9af commit e85924d

File tree

11 files changed

+105
-101
lines changed

11 files changed

+105
-101
lines changed

.github/workflows/php.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,10 @@ jobs:
3333
run: composer install --prefer-dist --no-progress
3434

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

3838
- name: Run stan
39-
run: vendor/bin/phpstan analyse ./src --level 4
39+
run: vendor/bin/phpstan analyse
4040

4141
- name: Run tests
4242
run: vendor/bin/phpunit --coverage-clover=coverage.xml

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
/nbproject
66
/phpunit.xml
77
/coverage.xml
8+
.phpunit.*

.travis.yml

Lines changed: 0 additions & 44 deletions
This file was deleted.

composer.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
"type": "cakephp-plugin",
66
"license": "MIT",
77
"require": {
8-
"php": ">=5.6",
9-
"cakephp/orm": "^3.4"
8+
"cakephp/orm": "~4.0"
109
},
1110
"require-dev": {
12-
"cakephp/cakephp": "~3.4.0",
13-
"cakephp/cakephp-codesniffer": "^3.0",
14-
"phpunit/phpunit": "^5.6|^6"
11+
"cakephp/cakephp": "~4.0",
12+
"cakephp/cakephp-codesniffer": "^4.0",
13+
"phpunit/phpunit": "^9.5",
14+
"phpstan/phpstan": "^2.0"
1515
},
1616
"autoload": {
1717
"psr-4": {
@@ -23,5 +23,10 @@
2323
"Cake\\Test\\": "vendor/cakephp/cakephp/tests",
2424
"Robotusers\\Chunk\\Test\\": "tests"
2525
}
26+
},
27+
"config": {
28+
"allow-plugins": {
29+
"dealerdirect/phpcodesniffer-composer-installer": true
30+
}
2631
}
2732
}

phpcs.xml.dist

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,16 @@
11
<?xml version="1.0"?>
2-
<ruleset name="CakePHP Core">
3-
<rule ref="./vendor/cakephp/cakephp-codesniffer/CakePHP/ruleset.xml"/>
2+
<ruleset name="Robotusers">
3+
<rule ref="CakePHP">
4+
<exclude name="CakePHP.Commenting.FunctionComment.Missing"/>
5+
<exclude name="CakePHP.Commenting.FunctionComment.MissingParamComment"/>
6+
<exclude name="CakePHP.Commenting.FunctionComment.MissingParamTag"/>
7+
<exclude name="CakePHP.NamingConventions.ValidTraitName"/>
8+
<exclude name="SlevomatCodingStandard.TypeHints.PropertyTypeHint"/>
9+
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint"/>
10+
<exclude name="SlevomatCodingStandard.TypeHints.ParameterTypeHint"/>
11+
<exclude name="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
12+
<exclude name="Generic.Files.LineLength"/>
13+
</rule>
14+
<file>src/</file>
15+
<file>tests/</file>
416
</ruleset>

phpstan.neon

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
parameters:
2+
level: 4
3+
# reportUnmatchedIgnoredErrors: false
4+
# treatPhpDocTypesAsCertain: false
5+
paths:
6+
- src/
7+
- tests/

src/Model/Behavior/ChunkBehavior.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/*
35
* The MIT License
46
*
@@ -30,13 +32,12 @@
3032

3133
class ChunkBehavior extends Behavior
3234
{
33-
3435
/**
3536
* Returns chunked result set.
3637
*
37-
* @param Query $query Query instance.
38+
* @param \Cake\ORM\Query $query Query instance.
3839
* @param array $config Config.
39-
* @return ResultSet
40+
* @return \Robotusers\Chunk\ORM\ResultSet
4041
*/
4142
public function chunk(Query $query, array $config = [])
4243
{

src/ORM/ResultSet.php

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/*
35
* The MIT License
46
*
@@ -45,7 +47,7 @@ class ResultSet implements ResultSetInterface
4547
/**
4648
* Query instance.
4749
*
48-
* @var Query
50+
* @var \Cake\ORM\Query
4951
*/
5052
protected $query;
5153

@@ -113,15 +115,15 @@ class ResultSet implements ResultSetInterface
113115
* @var array
114116
*/
115117
protected $_defaultConfig = [
116-
'size' => 1000
118+
'size' => 1000,
117119
];
118120

119121
/**
120122
* Constructor.
121123
*
122-
* @param Query $query Query object.
124+
* @param \Cake\ORM\Query $query Query object.
123125
* @param array $config Configuration.
124-
* @throws RuntimeException When query is not supported.
126+
* @throws \RuntimeException When query is not supported.
125127
*/
126128
public function __construct(Query $query, array $config = [])
127129
{
@@ -140,34 +142,36 @@ public function __construct(Query $query, array $config = [])
140142
}
141143

142144
/**
143-
* {@inheritDoc}
145+
* @inheritDoc
144146
*/
147+
#[\ReturnTypeWillChange]
145148
public function current()
146149
{
147150
return $this->current;
148151
}
149152

150153
/**
151-
* {@inheritDoc}
154+
* @inheritDoc
152155
*/
156+
#[\ReturnTypeWillChange]
153157
public function key()
154158
{
155159
return $this->index;
156160
}
157161

158162
/**
159-
* {@inheritDoc}
163+
* @inheritDoc
160164
*/
161-
public function next()
165+
public function next(): void
162166
{
163167
$this->index++;
164168
$this->chunkIndex++;
165169
}
166170

167171
/**
168-
* {@inheritDoc}
172+
* @inheritDoc
169173
*/
170-
public function rewind()
174+
public function rewind(): void
171175
{
172176
$this->index = 0;
173177
$this->page = 1;
@@ -176,9 +180,9 @@ public function rewind()
176180
}
177181

178182
/**
179-
* {@inheritDoc}
183+
* @inheritDoc
180184
*/
181-
public function valid()
185+
public function valid(): bool
182186
{
183187
if ($this->limit && $this->index >= $this->limit) {
184188
return false;
@@ -235,30 +239,40 @@ protected function fetchChunk()
235239
}
236240

237241
/**
238-
* {@inheritDoc}
242+
* @inheritDoc
239243
*/
240-
public function count()
244+
public function count(): int
241245
{
242246
throw new RuntimeException('Count is not supported yet.');
243247
}
244248

245249
/**
246-
* Serialization is not supported (yet).
247-
*
248250
* {@inheritDoc}
251+
*
252+
* Serialization is not supported (yet). *
249253
*/
250254
public function serialize()
251255
{
252256
throw new RuntimeException('You cannot serialize this result set.');
253257
}
254258

259+
public function __serialize(): array
260+
{
261+
throw new RuntimeException('You cannot serialize this result set.');
262+
}
263+
255264
/**
256-
* Serialization is not supported (yet).
257-
*
258265
* {@inheritDoc}
266+
*
267+
* Serialization is not supported (yet). *
259268
*/
260269
public function unserialize($serialized)
261270
{
262271
throw new RuntimeException('You cannot unserialize this result set.');
263272
}
273+
274+
public function __unserialize(array $data): void
275+
{
276+
throw new RuntimeException('You cannot unserialize this result set.');
277+
}
264278
}

tests/TestCase/Model/Behavior/ChunkBehaviorTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
/*
35
* The MIT License
46
*
@@ -37,7 +39,7 @@
3739
class ChunkBehaviorTest extends TestCase
3840
{
3941
public $fixtures = [
40-
'core.authors'
42+
'core.Authors',
4143
];
4244

4345
public function testChunk()
@@ -47,7 +49,7 @@ public function testChunk()
4749

4850
$behavior = new ChunkBehavior($table);
4951
$chunk = $behavior->chunk($query, [
50-
'size' => 100
52+
'size' => 100,
5153
]);
5254

5355
$this->assertInstanceOf(ResultSet::class, $chunk);

0 commit comments

Comments
 (0)