Skip to content

Commit dae2f77

Browse files
authored
Merge pull request #5518 from Gustry/php-cs-fixer-pre-commit
Php cs fixer pre commit
2 parents c672367 + a1e49a3 commit dae2f77

File tree

99 files changed

+1552
-1299
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1552
-1299
lines changed

.php-cs-fixer.dist.php

Lines changed: 63 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,67 @@
11
<?php
22

3-
$finder = PhpCsFixer\Finder::create()
4-
//->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php')
5-
->in(array(
6-
__DIR__.'/lizmap/modules/action',
7-
__DIR__.'/lizmap/modules/admin',
8-
__DIR__.'/lizmap/modules/dataviz',
9-
__DIR__.'/lizmap/modules/filter',
10-
__DIR__.'/lizmap/modules/lizmap',
11-
__DIR__.'/lizmap/modules/view',
12-
__DIR__.'/lizmap/plugins/',
13-
__DIR__.'/lizmap/app/responses',
14-
__DIR__.'/lizmap/scripts/',
15-
))
16-
//->exclude(__DIR__.'/lizmap/modules/proj4php/classes/')
17-
;
3+
use PhpCsFixer\Config;
4+
use PhpCsFixer\Finder;
5+
6+
$finder = Finder::create()
7+
// ->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php')
8+
->in(array(
9+
__DIR__.'/lizmap/modules/action',
10+
__DIR__.'/lizmap/modules/admin',
11+
__DIR__.'/lizmap/modules/dataviz',
12+
__DIR__.'/lizmap/modules/filter',
13+
__DIR__.'/lizmap/modules/lizmap',
14+
__DIR__.'/lizmap/modules/view',
15+
__DIR__.'/lizmap/plugins/',
16+
__DIR__.'/lizmap/app/responses',
17+
__DIR__.'/lizmap/scripts/',
18+
))
19+
// ->exclude(__DIR__.'/lizmap/modules/proj4php/classes/')
20+
;
21+
22+
$config = new Config();
1823

19-
$config = new PhpCsFixer\Config();
2024
return $config
21-
->setCacheFile(__DIR__.'/.php-cs-fixer.cache')
22-
->setRules([
23-
'@PSR2' => true,
24-
'@Symfony' => true,
25-
'@PhpCsFixer' => true,
26-
'array_syntax' => array('syntax'=>'long'),
27-
'method_argument_space'=> ['on_multiline' => 'ensure_fully_multiline'],
28-
'new_with_braces'=> true,
29-
'no_whitespace_in_blank_line'=> true,
30-
'no_whitespace_before_comma_in_array'=> true,
31-
'no_useless_return' => true,
32-
'no_unneeded_final_method'=> false,
33-
'no_unset_cast' => false,
34-
'no_leading_import_slash'=> true,
35-
'no_leading_namespace_whitespace'=> true,
36-
'no_extra_blank_lines'=> true,
37-
'no_empty_statement'=> true,
38-
'no_empty_comment'=> true,
39-
'object_operator_without_whitespace' => true,
40-
'ordered_class_elements' => false,
41-
'phpdoc_var_without_name' => true,
42-
'phpdoc_types' => true,
43-
'phpdoc_trim_consecutive_blank_line_separation' => true,
44-
'phpdoc_no_useless_inheritdoc' => true,
45-
'phpdoc_no_empty_return' => true,
46-
'phpdoc_add_missing_param_annotation' => true,
47-
'protected_to_private' => false,
48-
'semicolon_after_instruction' => true,
49-
'short_scalar_cast' => true,
50-
'simplified_null_return' => false,
51-
'simple_to_complex_string_variable' => false,
52-
'standardize_not_equals' => true,
53-
'standardize_increment' => true,
54-
'whitespace_after_comma_in_array' => true,
55-
'yoda_style'=>array(
56-
'always_move_variable' => false,
57-
'equal' => false,
58-
'identical' => false,
59-
'less_and_greater' => null,
60-
)
61-
])
62-
->setFinder($finder)
63-
;
25+
->setCacheFile(__DIR__.'/.php-cs-fixer.cache')
26+
->setRules(array(
27+
'@PSR2' => true,
28+
'@Symfony' => true,
29+
'@PhpCsFixer' => true,
30+
'array_syntax' => array('syntax' => 'long'),
31+
'method_argument_space' => array('on_multiline' => 'ensure_fully_multiline'),
32+
'new_with_braces' => true,
33+
'no_whitespace_in_blank_line' => true,
34+
'no_whitespace_before_comma_in_array' => true,
35+
'no_useless_return' => true,
36+
'no_unneeded_final_method' => false,
37+
'no_unset_cast' => false,
38+
'no_leading_import_slash' => true,
39+
'no_leading_namespace_whitespace' => true,
40+
'no_extra_blank_lines' => true,
41+
'no_empty_statement' => true,
42+
'no_empty_comment' => true,
43+
'object_operator_without_whitespace' => true,
44+
'ordered_class_elements' => false,
45+
'phpdoc_var_without_name' => true,
46+
'phpdoc_types' => true,
47+
'phpdoc_trim_consecutive_blank_line_separation' => true,
48+
'phpdoc_no_useless_inheritdoc' => true,
49+
'phpdoc_no_empty_return' => true,
50+
'phpdoc_add_missing_param_annotation' => true,
51+
'protected_to_private' => false,
52+
'semicolon_after_instruction' => true,
53+
'short_scalar_cast' => true,
54+
'simplified_null_return' => false,
55+
'simple_to_complex_string_variable' => false,
56+
'standardize_not_equals' => true,
57+
'standardize_increment' => true,
58+
'whitespace_after_comma_in_array' => true,
59+
'yoda_style' => array(
60+
'always_move_variable' => false,
61+
'equal' => false,
62+
'identical' => false,
63+
'less_and_greater' => null,
64+
),
65+
))
66+
->setFinder($finder)
67+
;

.pre-commit-config.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,12 @@ repos:
2828
files: \.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
2929
types: [ file ]
3030
additional_dependencies:
31-
- eslint@9.19.0
31+
- eslint@9.21.0
3232

33-
# - repo: local
34-
# hooks:
35-
# - id: php-cs-fixer
36-
# name: PHP CS Fixer
37-
# # To match value in Makefile
38-
# entry: ghcr.io/php-cs-fixer/php-cs-fixer:3.69-php8.1 fix --config .php-cs-fixer.dist.php --allow-risky=yes
39-
# language: docker_image
33+
- repo: local
34+
hooks:
35+
- id: php-cs-fixer
36+
name: PHP CS Fixer
37+
# To match value in Makefile
38+
entry: ghcr.io/php-cs-fixer/php-cs-fixer:3.69-php8.1 fix --config .php-cs-fixer.dist.php --allow-risky=yes
39+
language: docker_image

docker/lizmapConfig.ini.php.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;<?php die(''); ?>
1+
;<?php exit(''); ?>
22
;for security reasons , don't remove or modify the first line
33

44
hideSensitiveServicesProperties=1

docker/localconfig.ini.php.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
;<?php die(''); ?>
1+
;<?php exit(''); ?>
22
;for security reasons , don't remove or modify the first line
33

44
;theme=

docker/update-config.php

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,19 @@
11
#!/usr/bin/env php
22
<?php
3-
require('/www/lizmap/vendor/autoload.php');
4-
use \Jelix\IniFile\IniModifier;
3+
4+
require '/www/lizmap/vendor/autoload.php';
5+
use Jelix\IniFile\IniModifier;
56

67
/**
7-
* @param $varname
88
* @param IniModifier $iniFileModifier
9-
* @return void
109
*/
1110
function load_include_config($varname, $iniFileModifier)
1211
{
1312
$includeConfigDir = getenv($varname);
1413
if ($includeConfigDir !== false and is_dir($includeConfigDir)) {
15-
echo("Checking for lizmap configuration files in ".$includeConfigDir."\n");
16-
foreach (glob(rtrim($includeConfigDir,"/")."/*.ini.php") as $includeFile) {
17-
echo("* Loading lizmap configuration: ".$includeFile."\n");
14+
echo 'Checking for lizmap configuration files in '.$includeConfigDir."\n";
15+
foreach (glob(rtrim($includeConfigDir, '/').'/*.ini.php') as $includeFile) {
16+
echo '* Loading lizmap configuration: '.$includeFile."\n";
1817
$includeConfig = new IniModifier($includeFile);
1918
$iniFileModifier->import($includeConfig);
2019
}
@@ -29,29 +28,31 @@ function load_include_config($varname, $iniFileModifier)
2928
}
3029

3130
/**
32-
* connect to Postgresql with the given profile
31+
* connect to Postgresql with the given profile.
32+
*
3333
* @param array
34+
* @param mixed $profile
3435
*/
35-
function pgSqlConnect ($profile)
36+
function pgSqlConnect($profile)
3637
{
3738
$str = '';
3839

3940
// Service is PostgreSQL way to store credentials in a file :
4041
// http://www.postgresql.org/docs/9.1/static/libpq-pgservice.html
4142
// If given, no need to add host, user, database, port and password
42-
if(isset($profile['service']) && $profile['service'] != ''){
43+
if (isset($profile['service']) && $profile['service'] != '') {
4344
$str = 'service=\''.$profile['service'].'\''.$str;
4445

4546
// Database name may be given, even if service is used
4647
// dbname should not be mandatory in service file
4748
if (isset($profile['database']) && $profile['database'] != '') {
4849
$str .= ' dbname=\''.$profile['database'].'\'';
4950
}
50-
}
51-
else {
51+
} else {
5252
// we do a distinction because if the host is given == TCP/IP connection else unix socket
53-
if($profile['host'] != '')
53+
if ($profile['host'] != '') {
5454
$str = 'host=\''.$profile['host'].'\''.$str;
55+
}
5556

5657
if (isset($profile['port'])) {
5758
$str .= ' port=\''.$profile['port'].'\'';
@@ -82,29 +83,33 @@ function pgSqlConnect ($profile)
8283

8384
if (isset($profile['force_new']) && $profile['force_new']) {
8485
$cnx = pg_connect($str, PGSQL_CONNECT_FORCE_NEW);
85-
}
86-
else {
86+
} else {
8787
$cnx = pg_connect($str);
8888
}
8989

9090
// let's do the connection
9191
if ($cnx) {
9292
pg_close($cnx);
93+
9394
return true;
9495
}
96+
9597
return false;
9698
}
9799

98100
/**
99101
* Try to connect to the postgresql database.
100102
*
101103
* @param IniModifier $profilesConfig
102-
* @param string $profileName The profile to use
103-
* @param int $nbRetries
104+
* @param string $profileName The profile to use
105+
* @param int $nbRetries
106+
* @param mixed $wait
107+
*
104108
* @return bool
109+
*
105110
* @throws Exception
106111
*/
107-
function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $wait=2)
112+
function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries = 10, $wait = 2)
108113
{
109114
$origProfileName = $profileName;
110115
$profileAlias = $profilesConfig->getValue($profileName, 'jdb');
@@ -113,17 +118,18 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
113118
}
114119
$profile = $profilesConfig->getValues('jdb:'.$profileName);
115120
if ($profile === null) {
116-
throw new Exception("Database profile jdb:$profileName not found");
121+
throw new Exception("Database profile jdb:{$profileName} not found");
117122
}
118123
$profile = (new jDbParameters($profile))->getParameters();
119124
if ($profile['driver'] != 'pgsql') {
120125
return true;
121126
}
122127
$profile['timeout'] = 30;
123-
echo "trying to connect to the Postgresql database ".$profile['database']." at ".$profile['host']." with the profile $origProfileName...\n";
124-
for($i=0; $i < $nbRetries; $i++) {
128+
echo 'trying to connect to the Postgresql database '.$profile['database'].' at '.$profile['host']." with the profile {$origProfileName}...\n";
129+
for ($i = 0; $i < $nbRetries; ++$i) {
125130
if (pgSqlConnect($profile)) {
126131
echo " Ok, Postgresql is alive.\n";
132+
127133
return true;
128134
}
129135
// if there is nothing on the host/port, pg_connect fails immediately,
@@ -134,28 +140,29 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
134140
}
135141
echo "Error: cannot connect to the Postgresql database.\n";
136142
echo "Lizmap cannot starts.\n";
143+
137144
return false;
138145
}
139146

140147
/**
141-
* lizmapConfig.ini.php
148+
* lizmapConfig.ini.php.
142149
*/
143-
$lizmapConfig = new \Jelix\IniFile\IniModifier('/www/lizmap/var/config/lizmapConfig.ini.php');
150+
$lizmapConfig = new IniModifier('/www/lizmap/var/config/lizmapConfig.ini.php');
144151

145152
$lizmapConfig->setValue('wmsServerURL', getenv('LIZMAP_WMSSERVERURL'), 'services');
146153
$lizmapConfig->setValue('lizmapPluginAPIURL', getenv('LIZMAP_LIZMAPPLUGINAPIURL'), 'services');
147154
$lizmapConfig->setValue('rootRepositories', getenv('LIZMAP_ROOT_REPOSITORIES'), 'services');
148155
$lizmapConfig->setValue('relativeWMSPath', true, 'services');
149156

150-
foreach(array(
151-
'cacheExpiration' => 'LIZMAP_CACHEEXPIRATION',
152-
'debugMode' => 'LIZMAP_DEBUGMODE',
153-
'cacheStorageType' => 'LIZMAP_CACHESTORAGETYPE',
154-
'cacheRedisDb' => 'LIZMAP_CACHEREDISDB',
155-
'cacheRedisKeyPrefix' => 'LIZMAP_CACHEREDISKEYPREFIX',
156-
'cacheRedisHost' => 'LIZMAP_CACHEREDISHOST',
157-
'cacheRedisPort' => 'LIZMAP_CACHEREDISPORT',
158-
) as $key => $envValue
157+
foreach (array(
158+
'cacheExpiration' => 'LIZMAP_CACHEEXPIRATION',
159+
'debugMode' => 'LIZMAP_DEBUGMODE',
160+
'cacheStorageType' => 'LIZMAP_CACHESTORAGETYPE',
161+
'cacheRedisDb' => 'LIZMAP_CACHEREDISDB',
162+
'cacheRedisKeyPrefix' => 'LIZMAP_CACHEREDISKEYPREFIX',
163+
'cacheRedisHost' => 'LIZMAP_CACHEREDISHOST',
164+
'cacheRedisPort' => 'LIZMAP_CACHEREDISPORT',
165+
) as $key => $envValue
159166
) {
160167
if (getenv($envValue) !== false) {
161168
$lizmapConfig->setValue($key, getenv($envValue), 'services');
@@ -174,10 +181,10 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
174181
$lizmapConfig->save();
175182

176183
/**
177-
* localconfig.ini.php
184+
* localconfig.ini.php.
178185
*/
179-
$localConfig = new \Jelix\IniFile\IniModifier('/www/lizmap/var/config/localconfig.ini.php');
180-
$mainConfig = new \Jelix\IniFile\IniModifier('/www/lizmap/app/system/mainconfig.ini.php');
186+
$localConfig = new IniModifier('/www/lizmap/var/config/localconfig.ini.php');
187+
$mainConfig = new IniModifier('/www/lizmap/app/system/mainconfig.ini.php');
181188

182189
// Let's modify the install configuration of jcommunity, to not create a default
183190
// admin account (no `defaultusers` parameter). We're relying on
@@ -186,7 +193,6 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
186193
unset($jCommunityInstallParams['defaultusers']);
187194
$localConfig->setValue('jcommunity.installparam', $jCommunityInstallParams, 'modules');
188195

189-
190196
if ($logger_metric !== false) {
191197
$localConfig->setValue('metric', $logger_metric, 'logger');
192198
}
@@ -201,8 +207,7 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
201207
if (getenv('LIZMAP_PROXYURL_HTTPS_PORT') !== false) {
202208
$config['forceHTTPSPort'] = getenv('LIZMAP_PROXYURL_HTTPS_PORT');
203209
$localConfig->setValue('forceHTTPSPort', getenv('LIZMAP_PROXYURL_HTTPS_PORT'));
204-
}
205-
else {
210+
} else {
206211
$localConfig->setValue('forceHTTPSPort', 443);
207212
}
208213
}
@@ -236,7 +241,7 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
236241
$localConfig->save();
237242

238243
/**
239-
* profiles.ini.php
244+
* profiles.ini.php.
240245
*/
241246
$profilesConfig = new IniModifier('/www/lizmap/var/config/profiles.ini.php');
242247

@@ -260,9 +265,9 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
260265
// its table and so on.
261266
// Try with the default profile
262267
if (!checkAndWaitPostgresql($profilesConfig, 'default', $retries, $waits)) {
263-
exit (1);
268+
exit(1);
264269
}
265270
// try with the lizlog profile, it may be a different database.
266271
if (!checkAndWaitPostgresql($profilesConfig, 'lizlog', $retries, $waits)) {
267-
exit (1);
272+
exit(1);
268273
}

0 commit comments

Comments
 (0)