Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESLint files, and upgrade it to 9.20.1 in pre-commit, add PHP-CS-Fixer #5530

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 63 additions & 59 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,63 +1,67 @@
<?php

$finder = PhpCsFixer\Finder::create()
//->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php')
->in(array(
__DIR__.'/lizmap/modules/action',
__DIR__.'/lizmap/modules/admin',
__DIR__.'/lizmap/modules/dataviz',
__DIR__.'/lizmap/modules/filter',
__DIR__.'/lizmap/modules/lizmap',
__DIR__.'/lizmap/modules/view',
__DIR__.'/lizmap/plugins/',
__DIR__.'/lizmap/app/responses',
__DIR__.'/lizmap/scripts/',
))
//->exclude(__DIR__.'/lizmap/modules/proj4php/classes/')
;
use PhpCsFixer\Config;
use PhpCsFixer\Finder;

$finder = Finder::create()
// ->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php')
->in(array(
__DIR__.'/lizmap/modules/action',
__DIR__.'/lizmap/modules/admin',
__DIR__.'/lizmap/modules/dataviz',
__DIR__.'/lizmap/modules/filter',
__DIR__.'/lizmap/modules/lizmap',
__DIR__.'/lizmap/modules/view',
__DIR__.'/lizmap/plugins/',
__DIR__.'/lizmap/app/responses',
__DIR__.'/lizmap/scripts/',
))
// ->exclude(__DIR__.'/lizmap/modules/proj4php/classes/')
;

$config = new Config();

$config = new PhpCsFixer\Config();
return $config
->setCacheFile(__DIR__.'/.php-cs-fixer.cache')
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'@PhpCsFixer' => true,
'array_syntax' => array('syntax'=>'long'),
'method_argument_space'=> ['on_multiline' => 'ensure_fully_multiline'],
'new_with_braces'=> true,
'no_whitespace_in_blank_line'=> true,
'no_whitespace_before_comma_in_array'=> true,
'no_useless_return' => true,
'no_unneeded_final_method'=> false,
'no_unset_cast' => false,
'no_leading_import_slash'=> true,
'no_leading_namespace_whitespace'=> true,
'no_extra_blank_lines'=> true,
'no_empty_statement'=> true,
'no_empty_comment'=> true,
'object_operator_without_whitespace' => true,
'ordered_class_elements' => false,
'phpdoc_var_without_name' => true,
'phpdoc_types' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_add_missing_param_annotation' => true,
'protected_to_private' => false,
'semicolon_after_instruction' => true,
'short_scalar_cast' => true,
'simplified_null_return' => false,
'simple_to_complex_string_variable' => false,
'standardize_not_equals' => true,
'standardize_increment' => true,
'whitespace_after_comma_in_array' => true,
'yoda_style'=>array(
'always_move_variable' => false,
'equal' => false,
'identical' => false,
'less_and_greater' => null,
)
])
->setFinder($finder)
;
->setCacheFile(__DIR__.'/.php-cs-fixer.cache')
->setRules(array(
'@PSR2' => true,
'@Symfony' => true,
'@PhpCsFixer' => true,
'array_syntax' => array('syntax' => 'long'),
'method_argument_space' => array('on_multiline' => 'ensure_fully_multiline'),
'new_with_braces' => true,
'no_whitespace_in_blank_line' => true,
'no_whitespace_before_comma_in_array' => true,
'no_useless_return' => true,
'no_unneeded_final_method' => false,
'no_unset_cast' => false,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_extra_blank_lines' => true,
'no_empty_statement' => true,
'no_empty_comment' => true,
'object_operator_without_whitespace' => true,
'ordered_class_elements' => false,
'phpdoc_var_without_name' => true,
'phpdoc_types' => true,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_no_empty_return' => true,
'phpdoc_add_missing_param_annotation' => true,
'protected_to_private' => false,
'semicolon_after_instruction' => true,
'short_scalar_cast' => true,
'simplified_null_return' => false,
'simple_to_complex_string_variable' => false,
'standardize_not_equals' => true,
'standardize_increment' => true,
'whitespace_after_comma_in_array' => true,
'yoda_style' => array(
'always_move_variable' => false,
'equal' => false,
'identical' => false,
'less_and_greater' => null,
),
))
->setFinder($finder)
;
16 changes: 8 additions & 8 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ repos:
files: \.[jt]sx?$ # *.js, *.jsx, *.ts and *.tsx
types: [ file ]
additional_dependencies:
- eslint@9.19.0
- eslint@9.21.0

# - repo: local
# hooks:
# - id: php-cs-fixer
# name: PHP CS Fixer
# # To match value in Makefile
# entry: ghcr.io/php-cs-fixer/php-cs-fixer:3.69-php8.1 fix --config .php-cs-fixer.dist.php --allow-risky=yes
# language: docker_image
- repo: local
hooks:
- id: php-cs-fixer
name: PHP CS Fixer
# To match value in Makefile
entry: ghcr.io/php-cs-fixer/php-cs-fixer:3.69-php8.1 fix --config .php-cs-fixer.dist.php --allow-risky=yes
language: docker_image
2 changes: 1 addition & 1 deletion docker/lizmapConfig.ini.php.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;<?php die(''); ?>
;<?php exit(''); ?>
;for security reasons , don't remove or modify the first line

hideSensitiveServicesProperties=1
Expand Down
2 changes: 1 addition & 1 deletion docker/localconfig.ini.php.dist
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
;<?php die(''); ?>
;<?php exit(''); ?>
;for security reasons , don't remove or modify the first line

;theme=
Expand Down
87 changes: 46 additions & 41 deletions docker/update-config.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
#!/usr/bin/env php
<?php
require('/www/lizmap/vendor/autoload.php');
use \Jelix\IniFile\IniModifier;

require '/www/lizmap/vendor/autoload.php';
use Jelix\IniFile\IniModifier;

/**
* @param $varname
* @param IniModifier $iniFileModifier
* @return void
*/
function load_include_config($varname, $iniFileModifier)
{
$includeConfigDir = getenv($varname);
if ($includeConfigDir !== false and is_dir($includeConfigDir)) {
echo("Checking for lizmap configuration files in ".$includeConfigDir."\n");
foreach (glob(rtrim($includeConfigDir,"/")."/*.ini.php") as $includeFile) {
echo("* Loading lizmap configuration: ".$includeFile."\n");
echo 'Checking for lizmap configuration files in '.$includeConfigDir."\n";
foreach (glob(rtrim($includeConfigDir, '/').'/*.ini.php') as $includeFile) {
echo '* Loading lizmap configuration: '.$includeFile."\n";
$includeConfig = new IniModifier($includeFile);
$iniFileModifier->import($includeConfig);
}
Expand All @@ -29,29 +28,31 @@ function load_include_config($varname, $iniFileModifier)
}

/**
* connect to Postgresql with the given profile
* connect to Postgresql with the given profile.
*
* @param array
* @param mixed $profile
*/
function pgSqlConnect ($profile)
function pgSqlConnect($profile)
{
$str = '';

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

// Database name may be given, even if service is used
// dbname should not be mandatory in service file
if (isset($profile['database']) && $profile['database'] != '') {
$str .= ' dbname=\''.$profile['database'].'\'';
}
}
else {
} else {
// we do a distinction because if the host is given == TCP/IP connection else unix socket
if($profile['host'] != '')
if ($profile['host'] != '') {
$str = 'host=\''.$profile['host'].'\''.$str;
}

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

if (isset($profile['force_new']) && $profile['force_new']) {
$cnx = pg_connect($str, PGSQL_CONNECT_FORCE_NEW);
}
else {
} else {
$cnx = pg_connect($str);
}

// let's do the connection
if ($cnx) {
pg_close($cnx);

return true;
}

return false;
}

/**
* Try to connect to the postgresql database.
*
* @param IniModifier $profilesConfig
* @param string $profileName The profile to use
* @param int $nbRetries
* @param string $profileName The profile to use
* @param int $nbRetries
* @param mixed $wait
*
* @return bool
*
* @throws Exception
*/
function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $wait=2)
function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries = 10, $wait = 2)
{
$origProfileName = $profileName;
$profileAlias = $profilesConfig->getValue($profileName, 'jdb');
Expand All @@ -113,17 +118,18 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
}
$profile = $profilesConfig->getValues('jdb:'.$profileName);
if ($profile === null) {
throw new Exception("Database profile jdb:$profileName not found");
throw new Exception("Database profile jdb:{$profileName} not found");
}
$profile = (new jDbParameters($profile))->getParameters();
if ($profile['driver'] != 'pgsql') {
return true;
}
$profile['timeout'] = 30;
echo "trying to connect to the Postgresql database ".$profile['database']." at ".$profile['host']." with the profile $origProfileName...\n";
for($i=0; $i < $nbRetries; $i++) {
echo 'trying to connect to the Postgresql database '.$profile['database'].' at '.$profile['host']." with the profile {$origProfileName}...\n";
for ($i = 0; $i < $nbRetries; ++$i) {
if (pgSqlConnect($profile)) {
echo " Ok, Postgresql is alive.\n";

return true;
}
// if there is nothing on the host/port, pg_connect fails immediately,
Expand All @@ -134,28 +140,29 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
}
echo "Error: cannot connect to the Postgresql database.\n";
echo "Lizmap cannot starts.\n";

return false;
}

/**
* lizmapConfig.ini.php
* lizmapConfig.ini.php.
*/
$lizmapConfig = new \Jelix\IniFile\IniModifier('/www/lizmap/var/config/lizmapConfig.ini.php');
$lizmapConfig = new IniModifier('/www/lizmap/var/config/lizmapConfig.ini.php');

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

foreach(array(
'cacheExpiration' => 'LIZMAP_CACHEEXPIRATION',
'debugMode' => 'LIZMAP_DEBUGMODE',
'cacheStorageType' => 'LIZMAP_CACHESTORAGETYPE',
'cacheRedisDb' => 'LIZMAP_CACHEREDISDB',
'cacheRedisKeyPrefix' => 'LIZMAP_CACHEREDISKEYPREFIX',
'cacheRedisHost' => 'LIZMAP_CACHEREDISHOST',
'cacheRedisPort' => 'LIZMAP_CACHEREDISPORT',
) as $key => $envValue
foreach (array(
'cacheExpiration' => 'LIZMAP_CACHEEXPIRATION',
'debugMode' => 'LIZMAP_DEBUGMODE',
'cacheStorageType' => 'LIZMAP_CACHESTORAGETYPE',
'cacheRedisDb' => 'LIZMAP_CACHEREDISDB',
'cacheRedisKeyPrefix' => 'LIZMAP_CACHEREDISKEYPREFIX',
'cacheRedisHost' => 'LIZMAP_CACHEREDISHOST',
'cacheRedisPort' => 'LIZMAP_CACHEREDISPORT',
) as $key => $envValue
) {
if (getenv($envValue) !== false) {
$lizmapConfig->setValue($key, getenv($envValue), 'services');
Expand All @@ -174,10 +181,10 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
$lizmapConfig->save();

/**
* localconfig.ini.php
* localconfig.ini.php.
*/
$localConfig = new \Jelix\IniFile\IniModifier('/www/lizmap/var/config/localconfig.ini.php');
$mainConfig = new \Jelix\IniFile\IniModifier('/www/lizmap/app/system/mainconfig.ini.php');
$localConfig = new IniModifier('/www/lizmap/var/config/localconfig.ini.php');
$mainConfig = new IniModifier('/www/lizmap/app/system/mainconfig.ini.php');

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


if ($logger_metric !== false) {
$localConfig->setValue('metric', $logger_metric, 'logger');
}
Expand All @@ -201,8 +207,7 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
if (getenv('LIZMAP_PROXYURL_HTTPS_PORT') !== false) {
$config['forceHTTPSPort'] = getenv('LIZMAP_PROXYURL_HTTPS_PORT');
$localConfig->setValue('forceHTTPSPort', getenv('LIZMAP_PROXYURL_HTTPS_PORT'));
}
else {
} else {
$localConfig->setValue('forceHTTPSPort', 443);
}
}
Expand Down Expand Up @@ -236,7 +241,7 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
$localConfig->save();

/**
* profiles.ini.php
* profiles.ini.php.
*/
$profilesConfig = new IniModifier('/www/lizmap/var/config/profiles.ini.php');

Expand All @@ -260,9 +265,9 @@ function checkAndWaitPostgresql($profilesConfig, $profileName, $nbRetries=10, $w
// its table and so on.
// Try with the default profile
if (!checkAndWaitPostgresql($profilesConfig, 'default', $retries, $waits)) {
exit (1);
exit(1);
}
// try with the lizlog profile, it may be a different database.
if (!checkAndWaitPostgresql($profilesConfig, 'lizlog', $retries, $waits)) {
exit (1);
exit(1);
}
Loading
Loading