Browse Source

feat(dev-tools): Mise en place phpcs+phpstan (#4829)

Co-authored-by: JamesRezo <james@rezo.net>
Reviewed-on: #4829
Co-authored-by: JamesRezo <jamesrezo@noreply.git.spip.net>
Co-committed-by: JamesRezo <jamesrezo@noreply.git.spip.net>
remotes/checkIfPRContentChanged-1649837858812603111/master
JamesRezo 1 year ago
parent
commit
a838ad6a1f
  1. 7
      .gitignore
  2. 20
      action/deplacer_objets.php
  3. 4
      action/plan.php
  4. 7
      composer.json
  5. 15
      phpcs.xml.dist
  6. 132
      phpstan-baseline.neon
  7. 12
      phpstan.neon.dist
  8. 11
      plan_fonctions.php

7
.gitignore vendored

@ -0,0 +1,7 @@
/vendor/
/composer.phar
/composer.lock
/phpcs.xml
/phpstan.neon
/.php_cs.cache
/.php_cs.txt

20
action/deplacer_objets.php

@ -51,13 +51,13 @@ function action_deplacer_objets_dist() {
}
// ne modifier que si les emplacements n'ont pas déjà changé !
$ids = sql_allfetsel($_id_table, $table, array(sql_in($_id_table, $ids), $champ . '=' . sql_quote($id_rubrique_old)));
$ids = sql_allfetsel($_id_table, $table, [sql_in($_id_table, $ids), $champ . '=' . sql_quote($id_rubrique_old)]);
$ids = array_column($ids, $_id_table);
include_spip('action/editer_objet');
$errors = $success = array();
$modifs = array('id_parent' => $id_rubrique_new);
$errors = $success = [];
$modifs = ['id_parent' => $id_rubrique_new];
foreach ($ids as $id) {
if (autoriser('modifier', $objet, $id)) {
@ -77,7 +77,7 @@ function action_deplacer_objets_dist() {
$ids = sql_allfetsel(
$_id_table,
$table,
array(sql_in($_id_table, $ids), $champ . '=' . sql_quote($id_rubrique_old))
[sql_in($_id_table, $ids), $champ . '=' . sql_quote($id_rubrique_old)]
);
$ids = array_column($ids, $_id_table);
if ($ids) {
@ -88,11 +88,11 @@ function action_deplacer_objets_dist() {
}
}
return plan_json_envoi(array(
return plan_json_envoi([
'done' => true,
'success' => $success,
'errors' => $errors,
));
]);
}
function plan_json_envoi($data) {
@ -101,9 +101,9 @@ function plan_json_envoi($data) {
}
function plan_json_erreur($msg) {
return plan_json_envoi(array(
return plan_json_envoi([
'done' => false,
'success' => array(),
'errors' => array($msg)
));
'success' => [],
'errors' => [$msg]
]);
}

4
action/plan.php

@ -26,12 +26,12 @@ function action_plan_dist() {
include_spip('inc/utils');
$objet = table_objet(_request('objet'));
$env = array(
$env = [
'id_rubrique' => intval(_request('id_rubrique')),
// pour le dépliement d'une rubrique, ne pas lister le contenu récursivement
'lister' => ($objet == 'rubriques') ? 'rubrique' : 'tout',
'conteneur' => 'non'
);
];
if ($statut = _request('statut')) {
$env['statut'] = $statut;

7
composer.json

@ -0,0 +1,7 @@
{
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.7.1",
"spip/coding-standards": "^1.2",
"phpstan/phpstan": "^0.12.98"
}
}

15
phpcs.xml.dist

@ -0,0 +1,15 @@
<?xml version="1.0"?>
<ruleset>
<file>.</file>
<exclude-pattern>vendor/*</exclude-pattern>
<exclude-pattern>lang/*</exclude-pattern>
<exclude-pattern>lib/*</exclude-pattern>
<rule ref="SPIP41"/>
<config name="ignore_warnings_on_exit" value="1"/>
<arg name="cache" value=".php_cs.cache"/>
<arg name="report-full" value=".php_cs.txt"/>
<arg name="report-summary"/>
<arg value="s"/>
</ruleset>

132
phpstan-baseline.neon

@ -0,0 +1,132 @@
parameters:
ignoreErrors:
-
message: "#^Function _T not found\\.$#"
count: 11
path: action/deplacer_objets.php
-
message: "#^Function _request not found\\.$#"
count: 4
path: action/deplacer_objets.php
-
message: "#^Function autoriser not found\\.$#"
count: 2
path: action/deplacer_objets.php
-
message: "#^Function id_table_objet not found\\.$#"
count: 1
path: action/deplacer_objets.php
-
message: "#^Function include_spip not found\\.$#"
count: 3
path: action/deplacer_objets.php
-
message: "#^Function objet_modifier not found\\.$#"
count: 1
path: action/deplacer_objets.php
-
message: "#^Function objet_type not found\\.$#"
count: 1
path: action/deplacer_objets.php
-
message: "#^Function sql_allfetsel not found\\.$#"
count: 2
path: action/deplacer_objets.php
-
message: "#^Function sql_in not found\\.$#"
count: 2
path: action/deplacer_objets.php
-
message: "#^Function sql_quote not found\\.$#"
count: 2
path: action/deplacer_objets.php
-
message: "#^Function table_objet_sql not found\\.$#"
count: 1
path: action/deplacer_objets.php
-
message: "#^Function _request not found\\.$#"
count: 3
path: action/plan.php
-
message: "#^Function autoriser not found\\.$#"
count: 1
path: action/plan.php
-
message: "#^Function include_spip not found\\.$#"
count: 3
path: action/plan.php
-
message: "#^Function recuperer_fond not found\\.$#"
count: 1
path: action/plan.php
-
message: "#^Function table_objet not found\\.$#"
count: 1
path: action/plan.php
-
message: "#^Function trouver_fond not found\\.$#"
count: 1
path: action/plan.php
-
message: "#^Function charger_fonction not found\\.$#"
count: 1
path: plan_fonctions.php
-
message: "#^Function include_spip not found\\.$#"
count: 2
path: plan_fonctions.php
-
message: "#^Function lister_tables_objets_sql not found\\.$#"
count: 2
path: plan_fonctions.php
-
message: "#^Function session_get not found\\.$#"
count: 1
path: plan_fonctions.php
-
message: "#^Function statut_image not found\\.$#"
count: 1
path: plan_fonctions.php
-
message: "#^Function statut_titre not found\\.$#"
count: 1
path: plan_fonctions.php
-
message: "#^Function statuts_articles_visibles not found\\.$#"
count: 1
path: plan_fonctions.php
-
message: "#^Function trouver_fond not found\\.$#"
count: 1
path: plan_fonctions.php
-
message: "#^Function include_spip not found\\.$#"
count: 2
path: prive/squelettes/inclure/plan-articles_fonctions.php

12
phpstan.neon.dist

@ -0,0 +1,12 @@
includes:
- phpstan-baseline.neon
parameters:
paths:
- .
excludePaths:
analyseAndScan:
- vendor
- lang
- lib
level: 0

11
plan_fonctions.php

@ -1,4 +1,5 @@
<?php
/**
* Fonctions pour le plugin Plan du site dans l’espace privé
*
@ -60,7 +61,7 @@ function balise_PLAN_AFFICHER_LISTE_dist($p) {
function plan_lister_objets_rubrique() {
static $liste = null;
if (is_null($liste)) {
$liste = array();
$liste = [];
$tables = lister_tables_objets_sql();
unset($tables['spip_rubriques']);
foreach ($tables as $cle => $desc) {
@ -93,7 +94,7 @@ function plan_lister_objets_rubrique_statuts() {
if (is_null($liste)) {
$objets = plan_lister_objets_rubrique();
include_spip('inc/puce_statut');
$liste = array();
$liste = [];
foreach ($objets as $table => $null) {
$desc = lister_tables_objets_sql($table);
// l'objet possède un statut
@ -101,12 +102,12 @@ function plan_lister_objets_rubrique_statuts() {
$statuts = array_keys($desc['statut_textes_instituer']);
$objet = $desc['table_objet'];
// obtenir titre et image du statut
$_statuts = array();
$_statuts = [];
foreach ($statuts as $statut) {
$_statuts[$statut] = array(
$_statuts[$statut] = [
'image' => statut_image($objet, $statut),
'titre' => statut_titre($objet, $statut),
);
];
}
$liste[$objet] = $_statuts;
}

Loading…
Cancel
Save