Skip to content

Commit e458068

Browse files
committed
add phpcs.xml.dist
1 parent 7d64fd5 commit e458068

File tree

7 files changed

+41
-18
lines changed

7 files changed

+41
-18
lines changed

composer.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
}
3838
},
3939
"scripts": {
40-
"test": "phpunit"
40+
"test": "phpunit",
41+
"cs-check": "phpcs src/ tests/",
42+
"cs-fix": "phpcbf src/ tests/"
4143
},
4244
"extra": {
4345
"branch-alias": {

phpcs.xml.dist

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="CustomCakePHPCodeSniffer">
3+
4+
<exclude-pattern>tests/bootstrap.php</exclude-pattern>
5+
6+
<rule ref="vendor/cakephp/cakephp-codesniffer/CakePHP">
7+
<exclude name="CakePHP.Commenting"/>
8+
</rule>
9+
10+
</ruleset>
11+

src/Controller/Component/ApiPaginationComponent.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace BryanCrowe\ApiPagination\Controller\Component;
35

46
use Cake\Controller\Component;
@@ -19,7 +21,7 @@ class ApiPaginationComponent extends Component
1921
protected $_defaultConfig = [
2022
'key' => 'pagination',
2123
'aliases' => [],
22-
'visible' => []
24+
'visible' => [],
2325
];
2426

2527
/**
@@ -98,7 +100,8 @@ protected function setVisibility()
98100
*/
99101
protected function isPaginatedApiRequest()
100102
{
101-
if ($this->getController()->getRequest()->getAttribute('paging')
103+
if (
104+
$this->getController()->getRequest()->getAttribute('paging')
102105
&& $this->getController()->getRequest()->is(['json', 'xml'])
103106
) {
104107
return true;

tests/Fixture/ArticlesFixture.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class ArticlesFixture extends TestFixture
1111
'id' => ['type' => 'integer'],
1212
'title' => ['type' => 'string', 'null' => false],
1313
'body' => 'text',
14-
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]]
14+
'_constraints' => ['primary' => ['type' => 'primary', 'columns' => ['id']]],
1515
];
1616

1717
public $records = [
@@ -37,6 +37,6 @@ class ArticlesFixture extends TestFixture
3737
['title' => 'Post #20', 'body' => 'This is the article body.'],
3838
['title' => 'Post #21', 'body' => 'This is the article body.'],
3939
['title' => 'Post #22', 'body' => 'This is the article body.'],
40-
['title' => 'Post #23', 'body' => 'This is the article body.']
40+
['title' => 'Post #23', 'body' => 'This is the article body.'],
4141
];
4242
}

tests/TestCase/Controller/Component/ApiPaginationComponentTest.php

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace BryanCrowe\ApiPagination\Test;
35

46
use BryanCrowe\ApiPagination\Controller\Component\ApiPaginationComponent;
57
use BryanCrowe\ApiPagination\TestApp\Controller\ArticlesController;
68
use Cake\Event\Event;
79
use Cake\Http\ServerRequest as Request;
8-
use Cake\Http\Response;
910
use Cake\ORM\TableRegistry;
1011
use Cake\TestSuite\TestCase;
1112

@@ -108,15 +109,16 @@ public function testVisibilitySettings()
108109
);
109110
$this->controller->set('data', $this->controller->paginate($this->Articles));
110111
$apiPaginationComponent = new ApiPaginationComponent(
111-
$this->controller->components(), [
112+
$this->controller->components(),
113+
[
112114
'visible' => [
113115
'page',
114116
'current',
115117
'count',
116118
'prevPage',
117119
'nextPage',
118-
'pageCount'
119-
]
120+
'pageCount',
121+
],
120122
]
121123
);
122124
$event = new Event('Controller.beforeRender', $this->controller);
@@ -147,12 +149,13 @@ public function testAliasSettings()
147149
);
148150
$this->controller->set('data', $this->controller->paginate($this->Articles));
149151
$apiPaginationComponent = new ApiPaginationComponent(
150-
$this->controller->components(), [
152+
$this->controller->components(),
153+
[
151154
'aliases' => [
152155
'page' => 'curPage',
153156
'current' => 'currentCount',
154157
'count' => 'totalCount',
155-
]
158+
],
156159
]
157160
);
158161
$event = new Event('Controller.beforeRender', $this->controller);
@@ -195,8 +198,9 @@ public function testKeySetting()
195198
);
196199
$this->controller->set('data', $this->controller->paginate($this->Articles));
197200
$apiPaginationComponent = new ApiPaginationComponent(
198-
$this->controller->components(), [
199-
'key' => 'paging'
201+
$this->controller->components(),
202+
[
203+
'key' => 'paging',
200204
]
201205
);
202206
$event = new Event('Controller.beforeRender', $this->controller);
@@ -239,20 +243,21 @@ public function testAllSettings()
239243
);
240244
$this->controller->set('data', $this->controller->paginate($this->Articles));
241245
$apiPaginationComponent = new ApiPaginationComponent(
242-
$this->controller->components(), [
246+
$this->controller->components(),
247+
[
243248
'key' => 'fun',
244249
'aliases' => [
245250
'page' => 'currentPage',
246251
'count' => 'totalCount',
247-
'limit' => 'unusedAlias'
252+
'limit' => 'unusedAlias',
248253
],
249254
'visible' => [
250255
'currentPage',
251256
'totalCount',
252257
'limit',
253258
'prevPage',
254-
'nextPage'
255-
]
259+
'nextPage',
260+
],
256261
]
257262
);
258263
$event = new Event('Controller.beforeRender', $this->controller);

tests/bootstrap.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
unset($findRoot);
1414
chdir($root);
1515
if (file_exists($root . '/config/bootstrap.php')) {
16-
include $root . '/config/bootstrap.php';
16+
require $root . '/config/bootstrap.php';
1717
return;
1818
}
1919
require $root . '/vendor/cakephp/cakephp/tests/bootstrap.php';

tests/test_app/TestApp/Controller/ArticlesController.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace BryanCrowe\ApiPagination\TestApp\Controller;
35

46
use Cake\Controller\Controller;

0 commit comments

Comments
 (0)