This repository has been archived by the owner on Nov 2, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
PHP Standard recommandation
Le TOULLEC Martial edited this page Aug 27, 2019
·
1 revision
Page qui affichage les standards de recommandations pour écrire du PHP.
Le premier block de code contient l'exemple mal écrit et l'autre block contient l'exemple corrigé
Une variable doit être minimum de 3 caractères
$Variable_test = 1;
$variable = "aa";
$test = "Oui, c'est moi";
$id = $workflow->id;
function Machin_bidule_truc(){}
const idSiteManagerProfile = '1';
$variableTest = 1;
$variable = 'aa';
$test = "Oui, c'est moi";
$idWorkflow = $workflow->id;
function machinBiduleTruc(){}
const IDSITEMANAGERPROFILE = '1';
Pour info, du code commenté, peut être supprimé, les commentaires permettent de savoir qu'est ce que l'on fait.
//a
// a
$machin = 1;
$test = 2;
echo $machin;
function test1($a, $b)
{
return $a;
}
function test2($a)
{
return $a.$a;
}
echo test(1);
$machin = 1;
echo $machin;
function test1($a)
{
return $a;
}
echo test(1);
public static function getWorkflowStatesWithNbDocs($workflowId, $allStates = true)
{
// Reste du code
}
public static function getWorkflowStatesWithNbDocs(
$workflowId,
$allStates = true
)
{
// Reste du code
}
empêche de définir une variable
$meta = ($idDoc == false);
$meta = (false == $idDoc);
$meta['sigle_uo'] = $folder->id_div4;
$meta['code_uo'] = $codeUO;
$meta['sigle_uo'] = $folder->id_div4;
$meta['code_uo'] = $codeUO;
$machin = array();
$test = array(
'a' => 1,
'b' => 2
);
$machin = [];
$test = [
'a' => 1,
'b' => 2,
];
biduleFonction1($param1,$param2, $param3, $param4, $param5, $param6, $param7, $param8);
biduleFonction2($param1,$param2);
biduleFonction1(
$param1,
$param2,
$param3,
$param4,
$param5,
$param6,
$param7,
$param8
);
biduleFonction2($param1, $param2);
for($i=1;$i<(cfg('nb_id_div')+1);++$i)
{
$ignore[$i] = 'i_id_div'.$i;
}
foreach($index as $index => $row)
{
if($index==0){
$test = 1;
}else{
$test = 2;
}
}
foreach($tab as $index => $row)
{
$tab[] = $row;
}
foreach($tab as $index => $row)
{
$tab[] = $index;
}
foreach($tab as $index => $row)
{
$tab[$index] = $row."a";
}
$nbIdDiv = (cfg('nb_id_div') + 1);
for ($i = 1; $i < nbIdDiv; ++$i) {
$ignore[$i] = 'i_id_div'.$i;
}
foreach ($tab as $index => $row) {
if ($index == 0) {
$test = 1;
continue;
}
$test = 2;
}
foreach ($tab as $row) {
$tab[] = $row;
}
foreach (array_keys($tab ) as $index) {
$tab[] = $index;
}
foreach($tab as &$row)
{
$row = $row."a";
}
$meta = isset($ma)?$ma:null;
$meta = isset($ma) ? $ma : null;
if($machin=='a')
{
echo "oui";
}elseif($bidule=='b'){
echo "non";
}
if ($machin == 'a') {
echo "oui";
} elseif ($bidule == 'b') {
echo "non";
}
function machin($a){
return $a;
}
function machin($a)
{
return $a;
}
switch ($result) {
case 1:
Model_DocumentsDB::addToMetadata($document->id, 'adcf_date_relance_collab_7', date('Y-m-d H:i:s'));
break;
case 2:
Model_DocumentsDB::addToMetadata($document->id, 'adcf_date_relance_collab_14', date('Y-m-d H:i:s'));
break;
default:
return false;
}
switch ($result) {
case 1:
Model_DocumentsDB::addToMetadata(
$document->id,
'adcf_date_relance_collab_7',
date('Y-m-d H:i:s')
);
break;
case 2:
Model_DocumentsDB::addToMetadata(
$document->id,
'adcf_date_relance_collab_14',
date('Y-m-d H:i:s')
);
break;
default:
return false;
}
$query = $dql->execute()->fetchAll();
return $query;
return $dql->execute()->fetchAll();
function test($a, $b)
{
if ($a == $b) {
return false;
} else {
return true;
}
}
function test($a, $b)
{
if ($a == $b) {
return false;
}
return true;
}
$result1 = qb_update('eparapheur2_archive_action')->input($actionInfo)->where('id', $actionInfo['id'])->execute();
$result2 = qb_update('eparapheur2_archive_action')
->input($actionInfo)
->where('id', $actionInfo['id'])
->execute();
$dql = qb_update('eparapheur2_archive_action');
$qbl->input($actionInfo);
$qbl->where('id', $actionInfo['id']);
$result1 = $dql->execute();
$dql = qb_update('eparapheur2_archive_action');
$qbl->input($actionInfo);
$qbl->where('id', $actionInfo['id']);
$result2 = $dql->execute();
permet ainsi de savoir que la variable $tokenStorage provient de la classe TokenStorage
/** @var TokenStorage $tokenStorage */
$tokenStorage = $this->get('security.token_storage');