Skip to content

Commit d992ce0

Browse files
authored
Merge pull request #9 from tattersoftware/devtools
Update tools
2 parents bb6ea4e + c0f3e9c commit d992ce0

File tree

13 files changed

+151
-79
lines changed

13 files changed

+151
-79
lines changed

.gitattributes

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/.github export-ignore
2+
/docs export-ignore
3+
/examples export-ignore
4+
/tests export-ignore
5+
/.editorconfig export-ignore
6+
/.gitattributes export-ignore
7+
/.gitignore export-ignore
8+
/phpunit.xml.dist export-ignore
9+
/phpstan.neon.dist export-ignore
10+
11+
# Configure diff output for .php and .phar files.
12+
*.php diff=php
13+
*.phar -diff

.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

composer.json

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"name": "tatter/patches",
3+
"type": "library",
34
"description": "Module for updating CodeIgniter 4 projects",
45
"keywords": [
56
"codeigniter",
@@ -19,23 +20,14 @@
1920
"role": "Developer"
2021
}
2122
],
22-
"repositories": [
23-
{
24-
"type": "vcs",
25-
"url": "https://github.com/codeigniter4/CodeIgniter4"
26-
}
27-
],
28-
"minimum-stability": "dev",
29-
"prefer-stable": true,
3023
"require": {
31-
"php" : ">=7.2",
24+
"php": ">=7.2",
3225
"composer/composer": "^2.0",
3326
"sebastian/diff": "^3.0"
3427
},
3528
"require-dev": {
36-
"phpunit/phpunit": "8.5.*",
37-
"mikey179/vfsstream": "^1.6",
38-
"codeigniter4/codeigniter4": "dev-develop"
29+
"codeigniter4/codeigniter4": "dev-develop",
30+
"tatter/tools": "^1.0"
3931
},
4032
"autoload": {
4133
"psr-4": {
@@ -47,10 +39,17 @@
4739
"Tests\\Support\\": "tests/_support"
4840
}
4941
},
42+
"repositories": [
43+
{
44+
"type": "vcs",
45+
"url": "https://github.com/codeigniter4/CodeIgniter4"
46+
}
47+
],
48+
"minimum-stability": "dev",
49+
"prefer-stable": true,
5050
"scripts": {
51-
"test": "phpunit",
52-
"post-update-cmd": [
53-
"composer dump-autoload"
54-
]
51+
"analyze": "phpstan analyze",
52+
"style": "phpcs --standard=./vendor/codeigniter4/codeigniter4-standard/CodeIgniter4 tests/ src/",
53+
"test": "phpunit"
5554
}
5655
}

phpstan.neon.dist

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
parameters:
2+
tmpDir: build/phpstan
3+
level: 5
4+
paths:
5+
- src
6+
# - tests
7+
bootstrapFiles:
8+
- vendor/codeigniter4/codeigniter4/system/Test/bootstrap.php
9+
excludes_analyse:
10+
- src/Config/Routes.php
11+
- src/Views/*
12+
ignoreErrors:
13+
universalObjectCratesClasses:
14+
- CodeIgniter\Entity
15+
- Faker\Generator
16+
- Tatter\Patches\Codex
17+
scanDirectories:
18+
- vendor/codeigniter4/codeigniter4/system/Helpers
19+
dynamicConstantNames:
20+
- APP_NAMESPACE
21+
- CI_DEBUG
22+
- ENVIRONMENT

phpunit.xml.dist

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@
5151
<env name="COMPOSER_DISABLE_XDEBUG_WARN" value="1"/>
5252

5353
<!-- Database configuration -->
54-
<!-- <env name="database.tests.hostname" value="localhost"/> -->
55-
<!-- <env name="database.tests.database" value="tests"/> -->
56-
<!-- <env name="database.tests.username" value="tests_user"/> -->
57-
<!-- <env name="database.tests.password" value=""/> -->
58-
<!-- <env name="database.tests.DBDriver" value="MySQLi"/> -->
59-
<!-- <env name="database.tests.DBPrefix" value="tests_"/> -->
60-
<env name="database.tests.database" value=":memory:"/>
61-
<env name="database.tests.DBDriver" value="SQLite3"/>
54+
<!-- Uncomment to provide your own database for testing
55+
<env name="database.tests.hostname" value="localhost"/>
56+
<env name="database.tests.database" value="tests"/>
57+
<env name="database.tests.username" value="tests_user"/>
58+
<env name="database.tests.password" value=""/>
59+
<env name="database.tests.DBDriver" value="MySQLi"/>
60+
<env name="database.tests.DBPrefix" value="tests_"/>
61+
-->
6262
</php>
6363
</phpunit>

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

0 commit comments

Comments
 (0)