Skip to content

Commit 06a6820

Browse files
committed
PHPStan and Tests
1 parent 2951399 commit 06a6820

14 files changed

+396
-88
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
name: "Continuous Integration"
2+
3+
on:
4+
push:
5+
pull_request:
6+
schedule:
7+
- cron: '0 0 * * *'
8+
9+
jobs:
10+
phpunit:
11+
12+
runs-on: ubuntu-latest
13+
14+
strategy:
15+
fail-fast: true
16+
matrix:
17+
php: [8.0, 8.1]
18+
stability: [prefer-stable]
19+
20+
name: PHP ${{ matrix.php }} - ${{ matrix.stability }}
21+
22+
steps:
23+
- name: Checkout code
24+
uses: actions/checkout@v2
25+
26+
- name: Setup PHP
27+
uses: shivammathur/setup-php@v2
28+
with:
29+
php-version: ${{ matrix.php }}
30+
extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, memcached
31+
tools: composer:v2
32+
coverage: none
33+
34+
- name: Setup Memcached
35+
uses: niden/actions-memcached@v7
36+
37+
- name: Install dependencies
38+
uses: nick-invision/retry@v1
39+
with:
40+
timeout_minutes: 5
41+
max_attempts: 5
42+
command: composer update --${{ matrix.stability }} --prefer-dist --no-interaction --no-progress
43+
44+
- name: Execute tests
45+
run: vendor/bin/phpunit --verbose

.github/workflows/static-analysis.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: "Static Analysis"
2+
3+
on:
4+
push:
5+
paths:
6+
- .github/workflows/static-analysis.yml
7+
- composer.*
8+
- phpstan.neon.dist
9+
- src/**
10+
- tests/**
11+
12+
pull_request:
13+
paths:
14+
- .github/workflows/static-analysis.yml
15+
- composer.*
16+
- phpstan.neon.dist
17+
- src/**
18+
- tests/**
19+
20+
schedule:
21+
- cron: '0 0 * * *'
22+
23+
jobs:
24+
static-analysis-phpstan:
25+
name: "Static Analysis with PHPStan"
26+
runs-on: ubuntu-latest
27+
28+
strategy:
29+
matrix:
30+
php-version:
31+
- "8.1"
32+
33+
steps:
34+
- name: "Checkout code"
35+
uses: "actions/checkout@v2"
36+
37+
- name: "Install PHP"
38+
uses: "shivammathur/setup-php@v2"
39+
with:
40+
coverage: "none"
41+
php-version: "${{ matrix.php-version }}"
42+
tools: "cs2pr"
43+
44+
- name: "Install dependencies with Composer"
45+
uses: "ramsey/composer-install@v1"
46+
47+
- name: "Run a static analysis with phpstan/phpstan"
48+
run: "vendor/bin/phpstan --error-format=checkstyle | cs2pr"

composer.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
}
1616
],
1717
"require": {
18-
"php": ">=7.0",
19-
"yajra/laravel-datatables-oracle": "8.*|9.*",
20-
"league/fractal": "^0.19.0"
18+
"php": ">=8.0.2",
19+
"yajra/laravel-datatables-oracle": "^10.0",
20+
"league/fractal": "^0.19.2"
2121
},
2222
"require-dev": {
23-
"mockery/mockery": "0.9.*",
24-
"phpunit/phpunit": "~6.0"
23+
"nunomaduro/larastan": "^2.1",
24+
"orchestra/testbench": "^7.3"
2525
},
2626
"autoload": {
2727
"psr-4": {
@@ -30,12 +30,12 @@
3030
},
3131
"autoload-dev": {
3232
"psr-4": {
33-
"Yajra\\DataTables\\Tests\\": "tests/"
33+
"Yajra\\DataTables\\Fractal\\Tests\\": "tests/"
3434
}
3535
},
3636
"extra": {
3737
"branch-alias": {
38-
"dev-master": "1.0-dev"
38+
"dev-master": "9.0-dev"
3939
},
4040
"laravel": {
4141
"providers": [

phpstan.neon.dist

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
includes:
2+
- ./vendor/nunomaduro/larastan/extension.neon
3+
4+
parameters:
5+
6+
paths:
7+
- src
8+
9+
level: 5
10+
11+
ignoreErrors:
12+
- '#Access to an undefined property Yajra\\DataTables\\FractalServiceProvider::\$transformer.#'
13+
- '#Access to an undefined property Yajra\\DataTables\\FractalServiceProvider::\$serializer.#'
14+
15+
excludePaths:
16+
17+
checkMissingIterableValueType: false
18+
19+
checkGenericClassInNonGenericObjectType: false

phpunit.xml renamed to phpunit.xml.dist

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,10 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
>
1312
<testsuites>
1413
<testsuite name="Package Test Suite">
1514
<directory suffix=".php">./tests/</directory>
1615
</testsuite>
1716
</testsuites>
18-
<filter>
19-
<blacklist>
20-
<directory suffix=".php">./vendor</directory>
21-
</blacklist>
22-
</filter>
2317
</phpunit>

src/Commands/TransformerMakeCommand.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,13 @@ class TransformerMakeCommand extends GeneratorCommand
3333
/**
3434
* Replace the class name for the given stub.
3535
*
36-
* @param string $stub Contents of the stub
37-
* @param string $name The class name
38-
*
36+
* @param string $stub Contents of the stub
37+
* @param string $name The class name
3938
* @return string
4039
*/
41-
protected function replaceClass($stub, $name)
40+
protected function replaceClass($stub, $name): string
4241
{
43-
$stub = parent::replaceClass($stub, $name . 'Transformer');
42+
$stub = parent::replaceClass($stub, $name.'Transformer');
4443
$stub = str_replace('Dummy', ucfirst($this->argument('name')), $stub);
4544
$stub = str_replace('dummy', lcfirst($this->argument('name')), $stub);
4645

@@ -57,33 +56,31 @@ protected function replaceClass($stub, $name)
5756
*
5857
* @return string
5958
*/
60-
protected function getStub()
59+
protected function getStub(): string
6160
{
6261
return $this->argument('include') ?
63-
__DIR__ . '/stubs/transformer.inc.stub' :
64-
__DIR__ . '/stubs/transformer.stub';
62+
__DIR__.'/stubs/transformer.inc.stub' :
63+
__DIR__.'/stubs/transformer.stub';
6564
}
6665

6766
/**
6867
* Get the default namespace for the class.
6968
*
70-
* @param string $rootNamespace The root namespace
71-
*
69+
* @param string $rootNamespace The root namespace
7270
* @return string
7371
*/
74-
protected function getDefaultNamespace($rootNamespace)
72+
protected function getDefaultNamespace($rootNamespace): string
7573
{
7674
return $rootNamespace.'\Transformers';
7775
}
7876

7977
/**
8078
* Get the destination class path.
8179
*
82-
* @param string $name Name of the class with namespace
83-
*
80+
* @param string $name Name of the class with namespace
8481
* @return string
8582
*/
86-
protected function getPath($name)
83+
protected function getPath($name): string
8784
{
8885
$name = Str::replaceFirst($this->rootNamespace(), '', $name);
8986

src/FractalServiceProvider.php

Lines changed: 39 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ class FractalServiceProvider extends ServiceProvider
1515
*
1616
* @var bool
1717
*/
18-
protected $defer = false;
18+
protected bool $defer = false;
1919

2020
/**
2121
* Bootstrap the application events.
2222
*
2323
* @return void
2424
*/
25-
public function boot()
25+
public function boot(): void
2626
{
27-
$this->mergeConfigFrom(__DIR__ . '/../config/datatables-fractal.php', 'datatables-fractal');
27+
$this->mergeConfigFrom(__DIR__.'/../config/datatables-fractal.php', 'datatables-fractal');
2828
$this->publishAssets();
2929

3030
$this->registerMacro();
@@ -35,11 +35,11 @@ public function boot()
3535
*
3636
* @return void
3737
*/
38-
protected function publishAssets()
38+
protected function publishAssets(): void
3939
{
4040
$this->publishes(
4141
[
42-
__DIR__ . '/../config/datatables-fractal.php' => config_path('datatables-fractal.php'),
42+
__DIR__.'/../config/datatables-fractal.php' => config_path('datatables-fractal.php'),
4343
], 'datatables-fractal'
4444
);
4545
}
@@ -49,77 +49,65 @@ protected function publishAssets()
4949
*
5050
* @return void
5151
*/
52-
protected function registerMacro()
52+
protected function registerMacro(): void
5353
{
54-
DataTableAbstract::macro(
55-
'setTransformer', function ($transformer) {
56-
$this->transformer = [$transformer];
54+
DataTableAbstract::macro('setTransformer', function ($transformer) {
55+
$this->transformer = [$transformer];
5756

58-
return $this;
59-
}
60-
);
57+
return $this;
58+
});
6159

62-
DataTableAbstract::macro(
63-
'addTransformer', function ($transformer) {
64-
$this->transformer[] = $transformer;
60+
DataTableAbstract::macro('addTransformer', function ($transformer) {
61+
$this->transformer[] = $transformer;
6562

66-
return $this;
67-
}
68-
);
63+
return $this;
64+
});
6965

70-
DataTableAbstract::macro(
71-
'setSerializer', function ($serializer) {
72-
$this->serializer = $serializer;
66+
DataTableAbstract::macro('setSerializer', function ($serializer) {
67+
$this->serializer = $serializer;
7368

74-
return $this;
75-
}
76-
);
69+
return $this;
70+
});
7771
}
7872

7973
/**
8074
* Register the service provider.
8175
*
8276
* @return void
8377
*/
84-
public function register()
78+
public function register(): void
8579
{
86-
$this->app->singleton(
87-
'datatables.fractal', function () {
88-
$fractal = new Manager;
89-
$config = $this->app['config'];
90-
$request = $this->app['request'];
91-
92-
$includesKey = $config->get('datatables-fractal.includes', 'include');
93-
if ($request->get($includesKey)) {
94-
$fractal->parseIncludes($request->get($includesKey));
95-
}
80+
$this->app->singleton('datatables.fractal', function () {
81+
$fractal = new Manager;
82+
$config = $this->app['config'];
83+
$request = $this->app['request'];
84+
85+
$includesKey = $config->get('datatables-fractal.includes', 'include');
86+
if ($request->get($includesKey)) {
87+
$fractal->parseIncludes($request->get($includesKey));
88+
}
9689

97-
$serializer = $config->get('datatables-fractal.serializer', DataArraySerializer::class);
98-
$fractal->setSerializer(new $serializer);
90+
$serializer = $config->get('datatables-fractal.serializer', DataArraySerializer::class);
91+
$fractal->setSerializer(new $serializer);
9992

100-
return $fractal;
101-
}
102-
);
93+
return $fractal;
94+
});
10395

104-
$this->app->singleton(
105-
'datatables.transformer', function () {
106-
return new FractalTransformer($this->app->make('datatables.fractal'));
107-
}
108-
);
96+
$this->app->singleton('datatables.transformer', function () {
97+
return new FractalTransformer($this->app->make('datatables.fractal'));
98+
});
10999

110-
$this->commands(
111-
[
112-
TransformerMakeCommand::class,
113-
]
114-
);
100+
$this->commands([
101+
TransformerMakeCommand::class,
102+
]);
115103
}
116104

117105
/**
118106
* Get the services provided by the provider.
119107
*
120108
* @return array
121109
*/
122-
public function provides()
110+
public function provides(): array
123111
{
124112
return [
125113
'datatables.fractal',

0 commit comments

Comments
 (0)