[WIP] Add some test in CI to check that the code is clean #86
23
.Jenkinsfile
Normal file
23
.Jenkinsfile
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
pipeline {
|
||||||
|
agent none
|
||||||
|
stages {
|
||||||
|
stage('PHPStan (static analysis)') {
|
||||||
|
agent {
|
||||||
|
docker {
|
||||||
|
image 'php:8.2-cli'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
steps {
|
||||||
|
script {
|
||||||
|
sh 'curl -fsSL https://github.com/phpstan/phpstan/releases/download/1.10.41/phpstan.phar -o phpstan.phar'
|
||||||
|
sh 'php ./phpstan.phar analyse --configuration=phpstan.neon --memory-limit=512M --error-format=junit > phpstan-results.junit.xml'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
post {
|
||||||
|
always {
|
||||||
|
junit 'phpstan-results.junit.xml'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -263,6 +263,8 @@ class FormField {
|
||||||
protected $read_only = null;
|
protected $read_only = null;
|
||||||
protected $disabled = null;
|
protected $disabled = null;
|
||||||
private $storage = NULL;
|
private $storage = NULL;
|
||||||
|
protected $mandatory = null;
|
||||||
|
protected $hidden = null;
|
||||||
|
|
||||||
protected function __construct($label) {
|
protected function __construct($label) {
|
||||||
$this->storage = & $_SESSION;
|
$this->storage = & $_SESSION;
|
||||||
|
@ -638,7 +640,7 @@ class EmailInputFormField extends TextInputFormField {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(!empty($this->value) && !eregi('^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$',$this->value)){
|
if(!empty($this->value) && !preg_match('/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/i', $this->value)){
|
||||||
if($set_error) $this->error = 'Adresse email invalide';
|
if($set_error) $this->error = 'Adresse email invalide';
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
@ -794,7 +796,7 @@ class MultipleCheckBoxInputFormField extends FormField {
|
||||||
protected $mandatory = NULL;
|
protected $mandatory = NULL;
|
||||||
protected $list = array();
|
protected $list = array();
|
||||||
|
|
||||||
public function __construct($label, $mandatory=TRUE, $list) {
|
public function __construct($label, $list, $mandatory=TRUE) {
|
||||||
parent::__construct($label);
|
parent::__construct($label);
|
||||||
$this->mandatory = $mandatory;
|
$this->mandatory = $mandatory;
|
||||||
$this->list = $list;
|
$this->list = $list;
|
||||||
|
@ -877,7 +879,7 @@ class SelectFormField extends FormField {
|
||||||
protected $mandatory = NULL;
|
protected $mandatory = NULL;
|
||||||
protected $list = array();
|
protected $list = array();
|
||||||
|
|
||||||
public function __construct($label, $mandatory=TRUE, $list) {
|
public function __construct($label, $list, $mandatory=TRUE) {
|
||||||
parent::__construct($label);
|
parent::__construct($label);
|
||||||
$this->mandatory = $mandatory;
|
$this->mandatory = $mandatory;
|
||||||
$this->list = $list;
|
$this->list = $list;
|
||||||
|
@ -933,7 +935,7 @@ class RadioFormField extends FormField {
|
||||||
protected $mandatory = NULL;
|
protected $mandatory = NULL;
|
||||||
protected $list = array();
|
protected $list = array();
|
||||||
|
|
||||||
public function __construct($label, $mandatory=TRUE, $list, $default = null) {
|
public function __construct($label, $list, $mandatory=TRUE, $default = null) {
|
||||||
parent::__construct($label);
|
parent::__construct($label);
|
||||||
$this->mandatory = $mandatory;
|
$this->mandatory = $mandatory;
|
||||||
$this->list = $list;
|
$this->list = $list;
|
||||||
|
@ -995,7 +997,7 @@ class ButtonInputFormField extends FormField {
|
||||||
protected $event = NULL;
|
protected $event = NULL;
|
||||||
protected $action = NULL;
|
protected $action = NULL;
|
||||||
|
|
||||||
public function __construct($label,$mandatory=FALSE, $event, $action) {
|
public function __construct($label, $event, $action, $mandatory=FALSE) {
|
||||||
parent::__construct($label);
|
parent::__construct($label);
|
||||||
$this->mandatory = $mandatory;
|
$this->mandatory = $mandatory;
|
||||||
$this->event = $event;
|
$this->event = $event;
|
||||||
|
|
|
@ -74,8 +74,8 @@ function web_add($form, $admin_mail) {
|
||||||
foreach ( $domain_alias as $domain ) {
|
foreach ( $domain_alias as $domain ) {
|
||||||
$exec_cmd = 'web-add.sh add-alias '.escapeshellarg($form->getField('username')->getValue()).' ';
|
$exec_cmd = 'web-add.sh add-alias '.escapeshellarg($form->getField('username')->getValue()).' ';
|
||||||
$domain = trim($domain);
|
$domain = trim($domain);
|
||||||
$exec_cmd .= $domain.' '. $server_list;
|
$exec_cmd .= $domain;
|
||||||
sudoexec($exec_cmd, $exec_output, $exec_return);
|
sudoexec($exec_cmd, $exec_output2, $exec_return2);
|
||||||
}
|
}
|
||||||
$exec_return |= $exec_return2; // $exec_return == 0 if $exec_return == 0 && $exec_return2 == 0
|
$exec_return |= $exec_return2; // $exec_return == 0 if $exec_return == 0 && $exec_return2 == 0
|
||||||
array_push($exec_output, $exec_output2);
|
array_push($exec_output, $exec_output2);
|
||||||
|
@ -254,19 +254,19 @@ $form->addField('username', new AlphaNumericalTextInputFormField("Nom d'utilisat
|
||||||
$form->addField('domain', new DomainInputFormField("Nom de domaine", TRUE));
|
$form->addField('domain', new DomainInputFormField("Nom de domaine", TRUE));
|
||||||
$form->addField('domain_alias', new DomainListInputFormField("Alias (séparés par une virgule, sans espaces)", FALSE));
|
$form->addField('domain_alias', new DomainListInputFormField("Alias (séparés par une virgule, sans espaces)", FALSE));
|
||||||
$form->addField('password_random',
|
$form->addField('password_random',
|
||||||
new CheckboxInputFormField("Mot de passe aléatoire ?", FALSE));
|
new CheckBoxInputFormField("Mot de passe aléatoire ?", FALSE));
|
||||||
$form->getField('password_random')->setValue(TRUE);
|
$form->getField('password_random')->setValue(TRUE);
|
||||||
$form->addField('password', new PasswordInputFormField('Mot de passe', FALSE));
|
$form->addField('password', new PasswordInputFormField('Mot de passe', FALSE));
|
||||||
$form->getField('password')->setDisabled();
|
$form->getField('password')->setDisabled();
|
||||||
$form->addField('mysql_db',
|
$form->addField('mysql_db',
|
||||||
new CheckboxInputFormField("Créer une base de données MySQL ?",
|
new CheckBoxInputFormField("Créer une base de données MySQL ?",
|
||||||
FALSE));
|
FALSE));
|
||||||
$form->getField('mysql_db')->setValue(TRUE);
|
$form->getField('mysql_db')->setValue(TRUE);
|
||||||
$form->addField('mysql_dbname',
|
$form->addField('mysql_dbname',
|
||||||
new AlphaNumericalTextInputFormField("Nom de la base MySQL", FALSE, array(20,16)));
|
new AlphaNumericalTextInputFormField("Nom de la base MySQL", FALSE, array(20,16)));
|
||||||
|
|
||||||
$form->addField('mysql_password_random',
|
$form->addField('mysql_password_random',
|
||||||
new CheckboxInputFormField("Mot de passe MySQL aléatoire ?",
|
new CheckBoxInputFormField("Mot de passe MySQL aléatoire ?",
|
||||||
FALSE));
|
FALSE));
|
||||||
$form->getField('mysql_password_random')->setValue(TRUE);
|
$form->getField('mysql_password_random')->setValue(TRUE);
|
||||||
|
|
||||||
|
@ -344,7 +344,7 @@ if ($conf['cluster']) {
|
||||||
|
|
||||||
if ($conf['bindadmin']) {
|
if ($conf['bindadmin']) {
|
||||||
/* Quai13 specific: allow to switch between Gmail MX/Quai13 MX */
|
/* Quai13 specific: allow to switch between Gmail MX/Quai13 MX */
|
||||||
$form->addField('use_gmail_mxs', new CheckboxInputFormField("Utilisation des serveurs Gmail en MX ?", FALSE));
|
$form->addField('use_gmail_mxs', new CheckBoxInputFormField("Utilisation des serveurs Gmail en MX ?", FALSE));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (array_key_exists('php_versions', $conf) && is_array($conf['php_versions'])) {
|
if (array_key_exists('php_versions', $conf) && is_array($conf['php_versions'])) {
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
if ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST)) {
|
if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST)) {
|
||||||
$input_username = $_POST['login'];
|
$input_username = $_POST['login'];
|
||||||
$input_password = $_POST['passw'];
|
$input_password = $_POST['passw'];
|
||||||
|
|
||||||
|
|
|
@ -81,6 +81,7 @@ function is_mcluster_mode() {
|
||||||
function load_config_cluster($cluster) {
|
function load_config_cluster($cluster) {
|
||||||
global $conf;
|
global $conf;
|
||||||
$configfile = '../conf/config.'.$cluster.'.php';
|
$configfile = '../conf/config.'.$cluster.'.php';
|
||||||
|
$clusterconf = array(); // Fix static analysis. It's fully defined by config file.
|
||||||
test_exist($configfile);
|
test_exist($configfile);
|
||||||
require_once($configfile);
|
require_once($configfile);
|
||||||
$conf = array_merge($conf, $clusterconf);
|
$conf = array_merge($conf, $clusterconf);
|
||||||
|
|
6
phpstan-baseline.neon
Normal file
6
phpstan-baseline.neon
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
parameters:
|
||||||
|
ignoreErrors:
|
||||||
|
-
|
||||||
|
message: "#^Undefined variable\\: \\$error$#"
|
||||||
|
count: 3
|
||||||
|
path: lib/bdd.php
|
13
phpstan.neon
Normal file
13
phpstan.neon
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
includes:
|
||||||
|
- phpstan-baseline.neon
|
||||||
|
|
||||||
|
parameters:
|
||||||
|
level: 0
|
||||||
|
paths:
|
||||||
|
- htdocs
|
||||||
|
- lib
|
||||||
|
- evolibs
|
||||||
|
- inc
|
||||||
|
- tpl
|
||||||
|
- conf
|
||||||
|
- bin
|
|
@ -31,5 +31,3 @@ else {
|
||||||
echo '<p>Bienvenue, utilisez le menu ci-dessus pour administrer votre compte.</p>';
|
echo '<p>Bienvenue, utilisez le menu ci-dessus pour administrer votre compte.</p>';
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@
|
||||||
for ( $i=0; $i < count($alias_list); ++$i ) {
|
for ( $i=0; $i < count($alias_list); ++$i ) {
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
printf('<td>%s</td>',
|
printf('<td>%s</td>',
|
||||||
$alias_list[$i]['alias'], $alias_list[$i]['alias']);
|
$alias_list[$i]['alias']);
|
||||||
if (is_superadmin())
|
if (is_superadmin())
|
||||||
printf('<td><a href="/webadmin/%s/alias/delete/%s/">Supprimer</a></td>',
|
printf('<td><a href="/webadmin/%s/alias/delete/%s/">Supprimer</a></td>',
|
||||||
$domain, $alias_list[$i]['alias']);
|
$domain, $alias_list[$i]['alias']);
|
||||||
|
|
|
@ -62,7 +62,7 @@
|
||||||
printf('<td>%s</td>', $vhost_info['owner']);
|
printf('<td>%s</td>', $vhost_info['owner']);
|
||||||
}
|
}
|
||||||
printf('<td>%s</td>',
|
printf('<td>%s</td>',
|
||||||
$vhost_info['server_name'], $vhost_info['server_name']);
|
$vhost_info['server_name']);
|
||||||
|
|
||||||
if ($conf['cluster']) {
|
if ($conf['cluster']) {
|
||||||
if (empty($vhost_info['bdd']))
|
if (empty($vhost_info['bdd']))
|
||||||
|
|
Loading…
Reference in a new issue