Situation 1 - Nettoyage du code - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.

Name: Situation 1 - Nettoyage du code fullscreencopydownloadembedprint


Your result can be seen below.

Result of php executing





Full code of Situation 1 - Nettoyage du code.php

  1. <?php
  2.  
  3. function creer_une_nouvelle_categorie_avec_des_attributs(string $label, array $donneesDesAttributes, bool $creerLesAttributs = true): Category
  4. {
  5.     /** @var Category $category */
  6.     $category = CategoryRepository::getInstance()->findOneByLabel($label);
  7.     if (!$category instanceof Category) {
  8.         $catogeryBuilder = new CategoryBuilder();
  9.         $ma_nouvelle_categorie = $catogeryBuilder->createNewCategory();
  10.         $ma_nouvelle_categorie->setLabel($label);
  11.         foreach ($donneesDesAttributes as $label_de_l_attribut => $d) {
  12.             if ($creerLesAttributs and $d['create']) {
  13.                 $constructeur_d_attribut = new AttributeBuilder();
  14.                 $mon_nouvel_attribut = $constructeur_d_attribut->createNewAttribute($label_de_l_attribut);
  15.                 $mon_nouvel_attribut->setValueType($d['value_type']);
  16.             }
  17.             $ma_nouvelle_categorie->addAttribute($mon_nouvel_attribut);
  18.         }
  19.     }
  20.     $category = $ma_nouvelle_categorie;
  21.  
  22.     return $category;
  23. } 
File Description
  • Situation 1 - Nettoyage du code
  • PHP Code
  • 01 Feb-2021
  • 1014 Bytes
You can Share it: