Skip to content

Commit

Permalink
#70 clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
bfoujols committed Mar 28, 2024
1 parent 093ddfc commit 435e960
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 16 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Edu-Framework est une proposition d'architecture MVC pour la création de projet
- Début d'approche pour l'enseignement d'un framework (Symfony, Laravel ...)

> [!NOTE]
> L'ensemble de la documentation est disponible sur le [https://studoo-app.github.io/edu-framework-doc](https://studoo-app.github.io/edu-framework-doc/starter.html)
> L'ensemble de la documentation est disponible sur le [https://studoo-app.github.io/edu-framework-doc](https://studoo-app.github.io/edu-framework-doc/)
> [!IMPORTANT]
> Ce framework n'est pas adapté à une utilisation en production. Il est destiné à des fins pédagogiques.
1 change: 0 additions & 1 deletion app/Config/routes.yaml
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
test: Controller\HomeController
13 changes: 7 additions & 6 deletions src/EduFramework/Commands/CreateCliCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*/
#[AsCommand(
name: 'make:command',
description: 'Génération d une commande',
description: 'Génération command CLI',
)]
class CreateCliCommand extends Command
{
Expand Down Expand Up @@ -62,8 +62,8 @@ public function execute(InputInterface $input, OutputInterface $output): int

/**
* Fonction permettant le traitement de l'arg command-name passé à la commande
* afin de générer les différents noms et chemins nécéssaires
* @param string $arg
* afin de générer les différents noms et chemins nécessaires
* @param string $arg Nom de la commande
* @return array
*/
private function getNamesCollection(string $arg): array
Expand All @@ -80,8 +80,8 @@ private function getNamesCollection(string $arg): array

/**
* Fonction permettant de générer la classe PHP
* @param string $className
* @param string $nameCommand
* @param string $className Nom de la classe
* @param string $nameCommand Nom de la commande
* @return void
* @throws CommandAlreadyExistsException
*/
Expand Down Expand Up @@ -123,8 +123,9 @@ private function generateCommand(string $className, string $nameCommand): void
self::$stdOutput->writeln([
CommandBanner::getBanner(),
'Bienvenue dans la console ' . ConfigCore::getConfig('name'),
''
'',
]);
// Ajouter votre code ici
return Command::SUCCESS;
CODE);

Expand Down
16 changes: 8 additions & 8 deletions src/EduFramework/Commands/CreateControllerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ public function execute(InputInterface $input, OutputInterface $output): int
//Format controller-name arg
$namesCollection = self::getNamesCollection($input->getArgument('controller-name'));
//Generate route params in app/Config/routes.yaml
self::generateRoute($namesCollection["uri"], $namesCollection["uri"], $namesCollection["className"]);
$this->generateRoute($namesCollection["uri"], $namesCollection["uri"], $namesCollection["className"]);
//Generate Controller Class
self::generateController($namesCollection["className"], $namesCollection["twigPath"]);
$this->generateController($namesCollection["className"], $namesCollection["twigPath"]);
//Generation TWIG
self::generateView($namesCollection["twigDir"], $namesCollection["twigPath"]);
$this->generateView($namesCollection["twigDir"], $namesCollection["twigPath"]);
//Close command message
$io->success("Controller successfully generated");
return Command::SUCCESS;
Expand All @@ -75,15 +75,15 @@ public function execute(InputInterface $input, OutputInterface $output): int
private function getNamesCollection(string $arg): array
{

$pieces = preg_split('/(?=[A-Z])/', $arg);
array_shift($pieces);
$name = preg_split('/(?=[A-Z])/', $arg);
array_shift($name);

$className = ucfirst($arg)."Controller";
$uri = strtolower($arg);
$twig = strtolower($arg);

if(count($pieces) > 1) {
$twig = implode("_", array_map(function ($item) {return strtolower($item);}, $pieces));
if(count($name) > 1) {
$twig = implode("_", array_map(function ($item) {return strtolower($item);}, $name));
$uri = str_replace("_", "-", $twig);
}

Expand All @@ -108,7 +108,7 @@ private function generateController(string $className, string $twigPath): void
mkdir(self::CONTROLLER_DIR);
}

$filename = "./app/Controller/$className.php";
$filename = self::CONTROLLER_DIR . "$className.php";

if(file_exists($filename)) {
throw new ControllerAlreadyExistsException();
Expand Down

0 comments on commit 435e960

Please sign in to comment.