Skip to content

Commit 3baf873

Browse files
committed
Apply static analysis
1 parent 1e75a8f commit 3baf873

File tree

9 files changed

+94
-58
lines changed

9 files changed

+94
-58
lines changed

.github/workflows/analyze.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# When a PR is opened or a push is made, perform
2+
# a static analysis check on the code using PHPStan.
3+
name: PHPStan
4+
5+
on:
6+
pull_request:
7+
branches:
8+
- 'develop'
9+
paths:
10+
- 'src/**'
11+
- 'tests/**'
12+
- 'phpstan*'
13+
- '.github/workflows/analyze.yml'
14+
push:
15+
branches:
16+
- 'develop'
17+
paths:
18+
- 'src/**'
19+
- 'tests/**'
20+
- 'phpstan*'
21+
- '.github/workflows/analyze.yml'
22+
23+
jobs:
24+
build:
25+
name: Analyze code
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v2
30+
31+
- name: Setup PHP
32+
uses: shivammathur/setup-php@v2
33+
with:
34+
php-version: latest
35+
tools: composer, pecl, phpunit
36+
extensions: intl, json, mbstring, mysqlnd, xdebug, xml, sqlite3
37+
38+
- name: Get composer cache directory
39+
id: composer-cache
40+
run: echo "::set-output name=dir::$(composer config cache-files-dir)"
41+
42+
- name: Create composer cache directory
43+
run: mkdir -p ${{ steps.composer-cache.outputs.dir }}
44+
45+
- name: Cache composer dependencies
46+
uses: actions/cache@v2
47+
with:
48+
path: ${{ steps.composer-cache.outputs.dir }}
49+
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
50+
restore-keys: ${{ runner.os }}-composer-
51+
52+
- name: Create PHPStan cache directory
53+
run: mkdir -p build/phpstan
54+
55+
- name: Cache PHPStan results
56+
uses: actions/cache@v2
57+
with:
58+
path: build/phpstan
59+
key: ${{ runner.os }}-phpstan-${{ github.sha }}
60+
restore-keys: ${{ runner.os }}-phpstan-
61+
62+
- name: Install dependencies
63+
run: composer install --no-progress --no-interaction --prefer-dist --optimize-autoloader
64+
env:
65+
COMPOSER_AUTH: ${{ secrets.COMPOSER_AUTH }}
66+
67+
- name: Run static analysis
68+
run: vendor/bin/phpstan analyze

phpstan.neon.dist

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,17 @@ parameters:
33
level: 5
44
paths:
55
- src
6-
- tests
6+
# - tests
77
bootstrapFiles:
88
- vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php
99
excludes_analyse:
1010
- src/Config/Routes.php
1111
- src/Views/*
1212
ignoreErrors:
13-
- '#Cannot access property [\$a-z_]+ on (array|object)#'
14-
- '#Unsafe usage of new static\(\)*#'
1513
universalObjectCratesClasses:
1614
- CodeIgniter\Entity
1715
- Faker\Generator
16+
- Tatter\Patches\Codex
1817
scanDirectories:
1918
- vendor/codeigniter4/codeigniter4/system/Helpers
2019
dynamicConstantNames:

src/Codex.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
use CodeIgniter\Config\BaseConfig;
44
use JsonSerializable;
5+
use Tatter\Patches\Config\Patches;
56

67
/**
78
* Class Codex
@@ -13,7 +14,7 @@ class Codex implements JsonSerializable
1314
/**
1415
* Config file to use.
1516
*
16-
* @var Tatter\Patches\Config\Patches
17+
* @var Patches
1718
*/
1819
public $config;
1920

@@ -87,9 +88,9 @@ class Codex implements JsonSerializable
8788
/**
8889
* Initialize the configuration.
8990
*
90-
* @param BaseConfig $config
91+
* @param Patches $config
9192
*/
92-
public function __construct(BaseConfig $config)
93+
public function __construct(Patches $config)
9394
{
9495
$this->config = $config;
9596
}

src/Commands/SelfUpdate.php

Lines changed: 4 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class SelfUpdate extends BaseCommand
1414
/**
1515
* The library instance
1616
*
17-
* @var Tatter\Patches\Patches
17+
* @var Patches
1818
*/
1919
public $patches;
2020

@@ -103,11 +103,9 @@ protected function mergeMenu(): bool
103103
{
104104
case 'p':
105105
return true;
106-
break;
107106

108107
case 'q':
109108
return false;
110-
break;
111109

112110
case 'l':
113111
$this->showFiles($codex->changedFiles, 'Changed');
@@ -161,13 +159,9 @@ protected function conflictsMenu(): bool
161159

162160
switch (CLI::prompt('Selection?', ['l', 'g', 'o', 's', 'q']))
163161
{
164-
case 'p':
165-
return true;
166-
break;
167-
162+
case 'q':
168163
case 's':
169164
return false;
170-
break;
171165

172166
case 'l':
173167
$this->showFiles($codex->conflicts['changed'], 'Changed');
@@ -188,7 +182,6 @@ protected function conflictsMenu(): bool
188182
}
189183

190184
return true;
191-
break;
192185
}
193186

194187
// If a non-returning item was select then run the menu again
@@ -198,7 +191,7 @@ protected function conflictsMenu(): bool
198191
/**
199192
* Display and process the resolve menu
200193
*
201-
* @param array $files Array of files to list
194+
* @param string $file Path to the file
202195
* @param string $status Changed/Added/Deleted
203196
*
204197
* @return bool False to quit out of the whole process
@@ -219,16 +212,13 @@ protected function resolveMenu(string $file, string $status): bool
219212
{
220213
case 's':
221214
return true;
222-
break;
223215

224216
case 'q':
225217
return false;
226-
break;
227218

228219
case 'd':
229220
CLI::write($this->patches->diffFile($file));
230221
return $this->resolveMenu($file, $status);
231-
break;
232222

233223
case 'o':
234224
$current = $codex->workspace . 'current/' . $file;
@@ -243,9 +233,7 @@ protected function resolveMenu(string $file, string $status): bool
243233
{
244234
copy_path($current, $project);
245235
}
246-
247-
return true;
248-
break;
236+
break;
249237
}
250238

251239
return true;

src/Handlers/Mergers/GitHandler.php

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

src/Handlers/Updaters/ComposerHandler.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ class ComposerHandler extends BaseHandler implements UpdaterInterface
1313
* Call Composer programmatically to update all vendor files
1414
* https://stackoverflow.com/questions/17219436/run-composer-with-a-php-script-in-browser#25208897
1515
*
16-
* @param Codex $codex
17-
*
1816
* @throws UpdateException
1917
*/
2018
public function update()

src/Helpers/patches_helper.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,12 @@ function copy_path(string $file1, string $file2): bool
7676
* Copies a directory and all its contents to a destination directory
7777
* https://stackoverflow.com/a/2050909
7878
*
79-
* @param string $file1 Full path to the file
80-
* @param string $file2 Full path to the new file
79+
* @param string $dir1 Full path to the directory
80+
* @param string $dir2 Full path to the new directory
8181
*
8282
* @return bool Success or failure
8383
*/
84-
function copy_directory_recursive($dir1, $dir2, $mode = 0755)
84+
function copy_directory_recursive(string $dir1, string $dir2, $mode = 0755)
8585
{
8686
$handle = opendir($dir1);
8787

@@ -106,6 +106,8 @@ function copy_directory_recursive($dir1, $dir2, $mode = 0755)
106106
}
107107

108108
closedir($handle);
109+
110+
return true;
109111
}
110112
}
111113

src/Patches.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,21 @@ class Patches
3535
/**
3636
* Instance of the update handler.
3737
*
38-
* @var Tatter\Patches\Interfaces\UpdaterInterface
38+
* @var UpdaterInterface
3939
*/
4040
protected $updater;
4141

4242
/**
4343
* Instance of the merger handler.
4444
*
45-
* @var Tatter\Patches\Interfaces\MergerInterface
45+
* @var MergerInterface
4646
*/
4747
protected $merger;
4848

4949
/**
5050
* The Differ
5151
*
52-
* @var SebastianBergmann\Diff\Differ
52+
* @var Differ|null
5353
*/
5454
protected $differ;
5555

@@ -211,7 +211,7 @@ public function setWorkspace(string $path = null): self
211211
* Locate and load sources by their name.
212212
* Priority: App, other modules, Tatter\Patches
213213
*
214-
* @return array $name => $instance
214+
* @return $this
215215
*/
216216
protected function gatherSources(): self
217217
{
@@ -358,7 +358,7 @@ public function beforeUpdate(): self
358358
// Copy the prepatch files and store the list
359359
$this->codex->legacyFiles = $this->copyPaths($destination);
360360

361-
$s = $this->codex->legacyFiles == 1 ? '' : 's';
361+
$s = count($this->codex->legacyFiles) === 1 ? '' : 's';
362362
$this->status(count($this->codex->legacyFiles) . " legacy file{$s} copied to {$destination}");
363363

364364
// If events are allowed then trigger prepatch

src/Test/MockPatches.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public function copyPaths(string $destination): array
3333
public function update(): bool
3434
{
3535
// Force the MockUpdater handler
36-
$tmpUpdater = $this->config->updater;
37-
$this->config->updater = 'Tatter\Patches\Test\MockUpdater';
36+
$tmpUpdater = $this->codex->config->updater;
37+
$this->codex->config->updater = 'Tatter\Patches\Test\MockUpdater';
3838

3939
$result = parent::update();
4040

4141
// Restore the handler
42-
$this->config->updater = $tmpUpdater;
42+
$this->codex->config->updater = $tmpUpdater;
4343

4444
return $result;
4545
}
@@ -52,13 +52,13 @@ public function update(): bool
5252
public function merge(): bool
5353
{
5454
// Force the MockMerger handler
55-
$tmpMerger = $this->config->updater;
56-
$this->config->merger = 'Tatter\Patches\Test\MockMerger';
55+
$tmpMerger = $this->codex->config->updater;
56+
$this->codex->config->merger = 'Tatter\Patches\Test\MockMerger';
5757

5858
$result = parent::merge();
5959

6060
// Restore the handler
61-
$this->config->merger = $tmpMerger;
61+
$this->codex->config->merger = $tmpMerger;
6262

6363
return $result;
6464
}

0 commit comments

Comments
 (0)