Skip to content

Commit 6efcfd1

Browse files
committed
Add phpstan checks, fixes
Fix checker configuration Update scrutinizer configuration Clean code
1 parent d91f024 commit 6efcfd1

9 files changed

+59
-86
lines changed

.composer-require-checker.config.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
"ctype", "date", "fileinfo", "filter", "iconv", "json", "pcre", "reflection", "session", "simplexml", "spl", "xml",
66

7-
"curl", "gd", "intl", "mbstring", "mysqli", "zlib", "pdo", "pgsql", "gettext", "yaml",
7+
"curl", "gd", "intl", "mbstring", "mysqli", "zlib", "pdo", "pgsql", "gettext",
88

99
"exif", "pcntl"
1010
],
@@ -44,6 +44,8 @@
4444
"GALETTE_X_FORWARDED_FOR_INDEX",
4545
"_CURRENT_THEME_PATH",
4646
"GALETTE_URI",
47+
"GALETTE_DISPLAY_VERSION",
48+
"GALETTE_PHP_MIN",
4749
"_T",
4850
"__",
4951
"_Tn",
@@ -91,7 +93,11 @@
9193
"// Should not error (not used) but...",
9294
"mt_rand",
9395
"rand",
94-
"random_int"
96+
"random_int",
97+
98+
99+
"// Not detected, do not know why.",
100+
"Psr\\Http\\Server\\RequestHandlerInterface"
95101
],
96102
"scan-files": [
97103
"*.php",

.github/workflows/ci-linux.yml

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616

1717
strategy:
1818
matrix:
19-
php-versions: [ '7.4', '8.0', '8.1', '8.2' ]
19+
php-versions: [ '8.1', '8.2' ]
2020
coverage: [none]
2121
fail-fast: false
2222

@@ -30,51 +30,58 @@ jobs:
3030
tools: composer
3131
coverage: ${{ matrix.coverage }}
3232

33-
- name: Checkout plugin
34-
uses: actions/checkout@v2
35-
3633
- name: Checkout Galette core
37-
uses: actions/checkout@v2
34+
uses: actions/checkout@v3
3835
with:
3936
repository: galette/galette
4037
path: galette-core
4138
fetch-depth: 1
4239
ref: develop
4340

41+
- name: Checkout plugin
42+
uses: actions/checkout@v3
43+
with:
44+
path: galette-core/galette/plugins/plugin-maps
45+
4446
- name: Get composer cache directory
4547
id: composer-cache
4648
run: |
47-
mv composer.json.checker composer.json
48-
echo "::set-output name=dir::$(composer config cache-files-dir)"
49-
if: ${{ matrix.php-versions!= '7.2' && matrix.php-versions!= '7.3' }}
49+
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
5050
5151
- name: Cache dependencies
52-
uses: actions/cache@v2
52+
uses: actions/cache@v3
5353
with:
5454
path: ${{ steps.composer-cache.outputs.dir }}
5555
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
5656
restore-keys: ${{ runner.os }}-composer-
57-
if: ${{ matrix.php-versions!= '7.2' && matrix.php-versions!= '7.3' }}
5857

5958
- name: Install dependencies
6059
run: |
60+
cd galette-core/galette
6161
composer install --ignore-platform-reqs
62-
if: ${{ matrix.php-versions!= '7.2' && matrix.php-versions!= '7.3' }}
63-
64-
- name: Install CS only
65-
run: |
66-
composer require squizlabs/php_codesniffer
67-
if: ${{ matrix.php-versions== '7.2' || matrix.php-versions== '7.3' }}
6862
6963
- name: CS
7064
run: |
71-
vendor/bin/phpcs -n -p --standard=galette-core/phpcs-rules.xml lib/ ./*.php
65+
cd galette-core/galette/plugins/plugin-maps
66+
../../vendor/bin/phpcs -n -p --standard=../../../phpcs-rules.xml lib/ ./*.php
7267
7368
- name: Check missing symbols
7469
run: |
75-
vendor/bin/composer-require-checker check --config-file=.composer-require-checker.config.json
76-
if: ${{ matrix.php-versions!= '7.2' && matrix.php-versions!= '7.3' }}
70+
cd galette-core/galette/plugins/plugin-maps
71+
composer require maglnet/composer-require-checker -W
72+
vendor/bin/composer-require-checker check --config-file=.composer-require-checker.config.json ../../composer.json
73+
74+
- name: PHPStan checks
75+
run: |
76+
cd galette-core/galette/plugins/plugin-maps
77+
../../vendor/bin/phpstan analyze --ansi --memory-limit=2G --no-interaction --no-progress
78+
if: matrix.php-versions == '8.1'
7779

78-
- uses: actions/setup-node@v1
79-
- run: npm install
80-
- run: npm run-script build
80+
- name: Install Node
81+
uses: actions/setup-node@v3
82+
83+
- name: Build JS
84+
run: |
85+
cd galette-core/galette/plugins/plugin-maps
86+
npm install
87+
npm run-script build

.scrutinizer.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,14 @@ build:
1414
analysis:
1515
environment:
1616
php:
17-
version: 7.4
17+
version: 8.1
1818

1919
project_setup:
2020
override:
2121
- 'true'
2222
tests:
2323
override:
2424
- php-scrutinizer-run
25-
-
26-
command: phpcs-run
27-
use_website_config: true
2825
- js-scrutinizer-run
2926

3027
cache:

composer.json.checker

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

lib/GaletteMaps/Controllers/MapsController.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
class MapsController extends AbstractPluginController
6262
{
6363
/**
64-
* @var integer
64+
* @var array
6565
*/
6666
#[Inject("Plugin Galette Maps")]
6767
protected $module_info;
@@ -81,7 +81,7 @@ public function map(Request $request, Response $response): Response
8181
//public pages are not actives
8282
return $response
8383
->withStatus(301)
84-
->withHeader('Location', $this->router->urlFor('slash'));
84+
->withHeader('Location', $this->routeparser->urlFor('slash'));
8585
}
8686

8787
$coords = new Coordinates();
@@ -156,15 +156,14 @@ public function localizeMember(Request $request, Response $response, int $id = n
156156
//in member
157157
//FIXME: silent fallback is maybe not the best to do
158158
$member->load($this->login->id);
159-
$id = $this->login->id;
160159
}
161160
}
162161

163162
$coords = new Coordinates();
164163
$mcoords = $coords->getCoords($member->id);
165164

166165
$towns = false;
167-
if ($mcoords === false || count($mcoords) === 0) {
166+
if (count($mcoords) === 0) {
168167
if ($member->town != '') {
169168
$t = new NominatimTowns($this->preferences);
170169
$towns = $t->search(
@@ -188,13 +187,6 @@ public function localizeMember(Request $request, Response $response, int $id = n
188187

189188
if ($towns !== false) {
190189
$params['towns'] = $towns;
191-
}
192-
193-
if ($mcoords === false) {
194-
$this->flash->addMessage(
195-
'error_detected',
196-
_T('Coordinates has not been loaded. Maybe plugin tables does not exists in the database?', 'maps')
197-
);
198190
} elseif (count($mcoords) > 0) {
199191
$params['town'] = $mcoords;
200192
}

lib/GaletteMaps/Coordinates.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -90,15 +90,14 @@ public function getCoords($id)
9090
'Maps coordinates table does not exists',
9191
Analog::WARNING
9292
);
93-
return false;
9493
} else {
9594
Analog::log(
9695
'Unable to retrieve members coordinates for "' .
9796
$id . '". | ' . $e->getMessage(),
9897
Analog::WARNING
9998
);
10099
}
101-
return false;
100+
throw $e;
102101
}
103102
}
104103

@@ -207,7 +206,7 @@ public function listCoords()
207206
Analog::WARNING
208207
);
209208
}
210-
return false;
209+
throw $e;
211210
}
212211
}
213212

@@ -225,7 +224,6 @@ public function setCoords($id, $latitude, $longitude)
225224
global $zdb;
226225

227226
try {
228-
$res = null;
229227
$coords = $this->getCoords($id);
230228
if (count($coords) === 0) {
231229
//cordinates does not exists yet
@@ -254,8 +252,7 @@ public function setCoords($id, $latitude, $longitude)
254252
return ($results->count() > 0);
255253
} catch (\Exception $e) {
256254
Analog::log(
257-
'Unable to set coordinatates for member ' .
258-
$id_adh . ' | ' . $e->getMessage(),
255+
'Unable to set coordinates | ' . $e->getMessage(),
259256
Analog::ERROR
260257
);
261258
return false;

lib/GaletteMaps/NominatimTowns.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,6 @@ public function search($town, $country = null)
119119
//get request infos
120120
$infos = curl_getinfo($ch);
121121
if ($infos['http_code'] !== 200) {
122-
$trace = debug_backtrace();
123-
$caller = $trace[1];
124122
//At this point, core has been created, but is failing
125123
//to load in solr.
126124
throw new \RuntimeException(

lib/GaletteMaps/PluginGaletteMaps.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737

3838
namespace GaletteMaps;
3939

40+
use Galette\Core\Login;
4041
use Galette\Entity\Adherent;
4142
use Galette\Core\GalettePlugin;
4243

phpstan.neon

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
parameters:
2+
parallel:
3+
maximumNumberOfProcesses: 2
4+
level: 3
5+
paths:
6+
- lib/
7+
scanFiles:
8+
- _config.inc.php
9+
- ../../config/paths.inc.php
10+
- ../../config/config.inc.php.dist
11+
- ../../config/galette_tcpdf_config.php
12+
scanDirectories:
13+
- ../../includes/
14+
- ../../lib/

0 commit comments

Comments
 (0)