Browse Source

Déplacement de fichiers d’une première tentative pour ne pas confondre,

et petite passe de php-cs-fixer
master
Matthieu Marcillaud 1 year ago
parent
commit
b2515ac68e
  1. 7
      bin/autodoc
  2. 12
      old/Generator.php
  3. 154
      old/GeneratorOld.php
  4. 17
      old/Loader/AbstractLoader.php
  5. 18
      old/Loader/Collection.php
  6. 9
      old/Loader/LoaderInterface.php
  7. 2
      src/Application.php
  8. 21
      src/Checkout.php
  9. 9
      src/Command/FromDirectory.php
  10. 10
      src/Command/FromGit.php
  11. 7
      src/Command/FromPlugin.php
  12. 11
      src/Command/FromSpip.php
  13. 7
      src/Command/FromZone.php
  14. 9
      src/Context.php
  15. 6
      src/Exception/AutodocException.php
  16. 6
      src/Exception/ContextException.php
  17. 17
      src/Git.php
  18. 8
      src/Loader/LoaderInterface.php
  19. 24
      src/Package.php
  20. 5
      src/Stage/GitSpipStage.php
  21. 9
      src/Stage/GitStage.php
  22. 8
      src/Stage/PackageStage.php
  23. 1
      src/Stage/StageInterface.php

7
bin/autodoc

@ -3,12 +3,7 @@
/**
* Autodoc.
*
* phpDocumentor pour le code source de SPIP
*
* Cet exécutable charge l'application autodoc (= phpdocumentor + plugins pour SPIP)
* et utilise les mêmes arguments d'entrée que l'application phpDocumentor.
*
* Pour un usage simplifié, utiliser autodoc_helper.php
* Usage simplifié pour SPIP de phpDocumentor.
*/
$autoloader = __DIR__ . '/../vendor/autoload.php';

12
src/Generator.php → old/Generator.php

@ -5,8 +5,8 @@ namespace Spip\Autodoc;
use Spip\Autodoc\Loader\LoaderInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
class Generator {
class Generator
{
private SymfonyStyle $io;
private LoaderInterface $loader;
@ -15,14 +15,16 @@ class Generator {
$this->io = $io;
}
public function setLoader(LoaderInterface $loader) {
public function setLoader(LoaderInterface $loader)
{
$this->loader = $loader;
}
public function run() {
public function run()
{
$this->loader->load();
$directories = $this->loader->getDirectories();
dump($directories);
}
}
}

154
old/GeneratorOld.php

@ -44,7 +44,8 @@ class GeneratorOld
$this->setApplicationDirectories();
}
public function isVerbose() : bool {
public function isVerbose(): bool
{
return $this->output->isVerbose();
}
@ -56,14 +57,17 @@ class GeneratorOld
*
* @param string $branche Branche Git
**/
public function generateFromSpip($branche) {
public function generateFromSpip($branche)
{
$url = "https://git.spip.net/spip/spip.git";
$prefixe = $this->input->getOption('prefixe');
$ok = $this->createDirectories($prefixe)
&& $this->getGitSource($url, $branche, 'spip');
if (!$ok) return false;
if (!$ok) {
return false;
}
$titre = "";
@ -94,7 +98,8 @@ class GeneratorOld
* @param string $chemin Chemin dans le git Zone
* @param string $branche Branche
**/
public function generateFromZone($chemin, $branche = 'master') {
public function generateFromZone($chemin, $branche = 'master')
{
$zone = "https://git.spip.net/$chemin.git";
return $this->generateFromGit($zone, $branche);
}
@ -104,7 +109,8 @@ class GeneratorOld
*
* @param string $source URL Git
**/
public function generateFromGit($source, $branche = 'master') {
public function generateFromGit($source, $branche = 'master')
{
$prefixe = $this->input->getOption('prefixe');
$ok = $this->createDirectories($prefixe)
&& $this->getGitSource($source, $branche)
@ -120,7 +126,8 @@ class GeneratorOld
* @param bool $is_ready
* Indique si les préparatifs (création des répertoires) sont déjà faits
**/
public function generateFromDirectory($dir, $is_ready = false) {
public function generateFromDirectory($dir, $is_ready = false)
{
$prefixe = $this->input->getOption('prefixe');
$ok = true;
@ -128,7 +135,9 @@ class GeneratorOld
# forcer le chemin de la source spécifique
$this->options['dirs']['input'] = $dir;
$ok = $this->createDirectories($prefixe);
if (!$ok) return false;
if (!$ok) {
return false;
}
}
$this->retrouverInfoPaquetXml();
@ -155,8 +164,8 @@ class GeneratorOld
*
* @param string $file Chemin du fichier ou URL
**/
public function generateFromFile($file) {
public function generateFromFile($file)
{
$timerStart = microtime(true);
// Option boussole SPIP => topnav.
@ -237,7 +246,7 @@ class GeneratorOld
*
* Si la mise à jour ne modifie pas les fichiers,
* la documentation n'est pas à actualiser (retourne null).
*
*
* @param string $prefixe
* Préfixe de cette documentation
* @param array $description
@ -247,7 +256,8 @@ class GeneratorOld
* - null : ok, mais mise à jour inutile
* - False : erreur
**/
public function obtenir_fichiers_a_documenter($prefixe, $description) {
public function obtenir_fichiers_a_documenter($prefixe, $description)
{
$this->output->writeln("\n");
$titre = "Générer la documentation de $prefixe";
$this->output->writeln("<comment>$titre</comment>");
@ -305,7 +315,8 @@ class GeneratorOld
* @param string $outut_base
* Répertoire où on été enregistré les documentations
**/
public function generer_sommaire_documentations($presents, $output_base) {
public function generer_sommaire_documentations($presents, $output_base)
{
// générer un sommaire de toutes ces documentations
$this->output->writeln("Création du sommaire des documentations");
@ -344,12 +355,12 @@ class GeneratorOld
);
}
}
usort($plugins, function($a, $b) {
usort($plugins, function ($a, $b) {
return ($a['nom'] < $b['nom']) ? -1 : 1;
});
// charger Twig, générer la page et l'enregitrer
$loader = new \Twig_Loader_Filesystem( $this->dirs['helper'] . '/Template' );
$loader = new \Twig_Loader_Filesystem($this->dirs['helper'] . '/Template');
$twig = new \Twig_Environment($loader);
$topnav = $this->getOption('topnav', '');
@ -372,9 +383,10 @@ class GeneratorOld
* @param string $outut_base
* Répertoire où on été enregistré les documentations
**/
public function generer_json_documentations($plugins, $output_base) {
public function generer_json_documentations($plugins, $output_base)
{
$this->output->writeln("Création du json des documentations");
usort($plugins, function($a, $b) {
usort($plugins, function ($a, $b) {
return ($a['prefixe'] < $b['prefixe']) ? -1 : 1;
});
$plugins = array_column($plugins, null, 'prefixe');
@ -382,10 +394,10 @@ class GeneratorOld
unlink($file);
}
file_put_contents($file, json_encode(
$plugins,
$plugins,
JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE
));
}
}
/**
@ -396,13 +408,14 @@ class GeneratorOld
* URL du fichier source (svn) de la liste des docémentations à générer
* @return bool True si ok.
**/
public function actualiser_liste_source($file) {
public function actualiser_liste_source($file)
{
// supprimer l'ancienne rotation
if (file_exists( $this->files['autodoc.txt.bak'] )) {
if (file_exists($this->files['autodoc.txt.bak'])) {
unlink($this->files['autodoc.txt.bak']);
}
// rotation
if (file_exists( $this->files['autodoc.txt'] )) {
if (file_exists($this->files['autodoc.txt'])) {
copy($this->files['autodoc.txt'], $this->files['autodoc.txt.bak']);
unlink($this->files['autodoc.txt']);
}
@ -430,7 +443,7 @@ class GeneratorOld
}
return true;
}
}
/**
* Effacte une ou plusieurs documentations qui ne sont plus listés
@ -443,7 +456,8 @@ class GeneratorOld
* @return bool
* True si au moins une documentation, et ses caches, ont été effacés.
**/
public function supprimer_vieux_plugins($absents, $output_base) {
public function supprimer_vieux_plugins($absents, $output_base)
{
if ($absents) {
$this->output->writeln("<comment>Certaines documentations ne sont plus à générer.</comment>");
foreach ($absents as $prefixe=>$absent) {
@ -471,15 +485,24 @@ class GeneratorOld
* - source : url du git
* - branche : branche à utiliser (défaut : master)
**/
private function parseFile($file, $write_errors = true) {
if (!file_exists($file)) return false;
if (!$lines = file($file)) return false;
private function parseFile($file, $write_errors = true)
{
if (!file_exists($file)) {
return false;
}
if (!$lines = file($file)) {
return false;
}
$liste = array();
foreach ($lines as $lineno => $line) {
if (!$line) continue;
if (!$line) {
continue;
}
$line = trim($line);
if (!$line OR $line[0] == '#') continue;
if (!$line or $line[0] == '#') {
continue;
}
$couples = explode(';', $line);
$lineno++;
if (count($couples) != 2) {
@ -526,14 +549,16 @@ class GeneratorOld
*
* @return bool true si réussi
**/
private function clearLogs() {
private function clearLogs()
{
return $this->deleteDirectoryContent($this->dirs['log']);
}
/**
* Définit les répertoires utiles à l'application
**/
private function setApplicationDirectories() {
private function setApplicationDirectories()
{
# ce répertoire
$this->dirs['helper'] = realpath(__DIR__);
@ -545,7 +570,7 @@ class GeneratorOld
$this->dirs['work'] = $this->dirs['root'] . '/work';
# répertoire du template zora
$this->dirs['template'] = realpath( $this->dirs['helper'] . '/../../../templates/zora');
$this->dirs['template'] = realpath($this->dirs['helper'] . '/../../../templates/zora');
# fichier de config xml pour phpdocumentor
$this->files['phpdoc.xml'] = $this->dirs['work'] . '/phpdoc.xml';
@ -558,7 +583,8 @@ class GeneratorOld
* @param string $prefixe Préfixe utilisé pour cette génération
* @return bool true si réussi
**/
private function createDirectories($prefixe) {
private function createDirectories($prefixe)
{
$_work = $this->dirs['work'];
$this->output->writeln("* Vérifier/créer les répertoires de travail dans <info>$_work</info>");
@ -583,7 +609,7 @@ class GeneratorOld
}
foreach (array('output', 'input', 'log', 'cache') as $dir) {
if (!$this->createDirectory( $this->dirs[$dir] )) {
if (!$this->createDirectory($this->dirs[$dir])) {
return false;
}
}
@ -600,7 +626,8 @@ class GeneratorOld
* @param string $chemin Répertoire à créer
* @return bool true si réussi
**/
private function createDirectory($dir) {
private function createDirectory($dir)
{
if (!is_dir($dir)) {
$this->output->writeln(" - Création du répertoire <info>$dir</info>");
@ -610,7 +637,6 @@ class GeneratorOld
$this->output->writeln($error['message']);
return false;
}
}
if (!is_writable($dir)) {
$this->output->writeln("<error>Le répertoire $dir n'est pas accessible en écriture</error>");
@ -627,7 +653,8 @@ class GeneratorOld
* @param string $branch Branche à utiliser
* @return bool true si réussi
**/
private function getGitSource(string $source, string $branch, string $type = 'git') : bool {
private function getGitSource(string $source, string $branch, string $type = 'git'): bool
{
$this->output->writeln("* Obtenir <info>$source</info>");
$this->git = array();
@ -637,7 +664,7 @@ class GeneratorOld
if (!$urlGit or $urlGit !== $source) {
// erreur, donc pas un dossier ou pas le bon
$this->output->writeln("<comment> - Source absente ou mauvaise, on le recrée</comment>");
$this->deleteDirectoryContent($this->dirs['input'], true);
$this->deleteDirectoryContent($this->dirs['input'], true);
}
$checkout->run("$type -b$branch $source");
@ -654,7 +681,8 @@ class GeneratorOld
* @param bool $no_error true : Envoie les erreurs dans /dev/null
* @return mixed|bool false en cas d'erreur
**/
private function getCheckout() : Checkout {
private function getCheckout(): Checkout
{
$dir = $this->dirs['input'];
return new Checkout($dir, new ConsoleLogger($this->output));
}
@ -666,7 +694,8 @@ class GeneratorOld
* @param bool $no_error true : Envoie les erreurs dans /dev/null
* @return mixed|bool false en cas d'erreur
**/
private function makeCheckoutCommand($cmd, $no_error = true, $dir = null) {
private function makeCheckoutCommand($cmd, $no_error = true, $dir = null)
{
if (is_null($dir)) {
$dir = $this->dirs['input'];
}
@ -685,15 +714,24 @@ class GeneratorOld
* @param string $delete_me Supprimer aussi le répertoire ?
* @return bool Suppression reussie.
*/
function deleteDirectoryContent($dir, $delete_me = false) {
if (!file_exists($dir)) return true;
if (!is_dir($dir) || is_link($dir)) return @unlink($dir);
public function deleteDirectoryContent($dir, $delete_me = false)
{
if (!file_exists($dir)) {
return true;
}
if (!is_dir($dir) || is_link($dir)) {
return @unlink($dir);
}
foreach (scandir($dir) as $item) {
if ($item == '.' || $item == '..') continue;
if ($item == '.' || $item == '..') {
continue;
}
if (!$this->deleteDirectoryContent($dir . "/" . $item, true)) {
@chmod($dir . "/" . $item, 0777);
if (!$this->deleteDirectoryContent($dir . "/" . $item, true)) return false;
if (!$this->deleteDirectoryContent($dir . "/" . $item, true)) {
return false;
}
};
}
@ -711,7 +749,8 @@ class GeneratorOld
* @param string $name Nom de l'option
* @return mixed
**/
private function getOption($name, $default = null) {
private function getOption($name, $default = null)
{
if (strpos($name, '/') === false) {
if ($this->input->hasOption($name) and $valeur = $this->input->getOption($name)) {
return $valeur;
@ -753,7 +792,8 @@ class GeneratorOld
* @param string $name Nom de l'option
* @param string $value Valeur de l'option
**/
private function setOption($name, $value) {
private function setOption($name, $value)
{
$name = explode('/', $name);
$n = array_shift($name);
$pointeur = &$this->options;
@ -773,7 +813,8 @@ class GeneratorOld
* @param string $command Nom de la commande
* @return mixed
**/
private function getCommand($command) {
private function getCommand($command)
{
if (isset($this->commands[$command])) {
$val = $this->commands[$command];
return " --$command=\"$val\"";
@ -787,7 +828,8 @@ class GeneratorOld
* @param string $command Nom de la commande
* @param string $value Valeur de la commande
**/
private function setCommand($command, $value) {
private function setCommand($command, $value)
{
$this->commands[$command] = $value;
}
@ -800,7 +842,8 @@ class GeneratorOld
*
* @return bool true si on a trouvé un paquet.xml
**/
private function retrouverInfoPaquetXml() {
private function retrouverInfoPaquetXml()
{
$source = $this->dirs['input'];
$is_spip = false;
@ -873,7 +916,6 @@ class GeneratorOld
}
if (!$this->getOption('presentation')) {
if ($is_spip) {
$presentation = "Cette documentation est issue du code source PHP de SPIP $version.&#13;&#10;&#13;&#10;";
} else {
@ -889,7 +931,7 @@ class GeneratorOld
$presentation = "Cette documentation est issue du code source PHP du plugin « ".$nom." », version $version$rev.&#13;&#10;&#13;&#10;";
}
if (!$is_spip OR $documentation OR $developpement) {
if (!$is_spip or $documentation or $developpement) {
if (!$is_spip) {
$presentation .= "- [Description dans l'annuaire des plugins]($lien_plugins_spip)&#13;&#10;";
}
@ -912,8 +954,8 @@ class GeneratorOld
*
* @return bool true si réussi.
**/
private function prepareConfigXml() {
private function prepareConfigXml()
{
$this->output->write("* Préparer le fichier phpdoc.xml ");
$template = $this->dirs['helper'] . '/phpdoc_helper.xml';
$template = file_get_contents($template);
@ -958,7 +1000,8 @@ class GeneratorOld
*
* @return bool true si réussi.
**/
private function execute() {
private function execute()
{
$conf = $this->files['phpdoc.xml'];
$command = "php phpDocumentor.phar --config=$conf";
if ($this->getOption('force')) {
@ -979,7 +1022,8 @@ class GeneratorOld
* @param string $string
* @return string
**/
private function escape_xml_attr($string) {
private function escape_xml_attr($string)
{
return htmlspecialchars($string, ENT_QUOTES, 'UTF-8');
}
}

17
src/Loader/AbstractLoader.php → old/Loader/AbstractLoader.php

@ -5,9 +5,8 @@ namespace Spip\Autodoc\Loader;
use Spip\Autodoc\Loader\LoaderInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
abstract class AbstractLoader implements LoaderInterface {
abstract class AbstractLoader implements LoaderInterface
{
protected SymfonyStyle $io;
private string $inputDirectory;
@ -16,17 +15,17 @@ abstract class AbstractLoader implements LoaderInterface {
$this->io = $io;
}
abstract public function load() : void;
abstract public function load(): void;
/**
* Get the value of directories to document
*/
*/
public function getDirectories(): array
{
return [ $this->inputDirectory ];
}
public function setInputDirectory(string $directory) : self
public function setInputDirectory(string $directory): self
{
$this->inputDirectory = $directory;
@ -35,9 +34,9 @@ abstract class AbstractLoader implements LoaderInterface {
/**
* Get the value of inputDirectory
*/
public function getInputDirectory() : string
*/
public function getInputDirectory(): string
{
return $this->inputDirectory;
}
}
}

18
src/Loader/Collection.php → old/Loader/Collection.php

@ -2,22 +2,24 @@
namespace Spip\Autodoc\Loader;
class Collection implements LoaderInterface {
class Collection implements LoaderInterface
{
/** @var LoaderInterface[] */
private array $loaders;
public function add(LoaderInterface $loader) {
public function add(LoaderInterface $loader)
{
$this->loaders[] = $loader;
}
public function load() : void {
public function load(): void
{
foreach ($this->loaders as $loader) {
$loader->load();
}
}
public function getDirectories(): array
public function getDirectories(): array
{
$dirs = [];
foreach ($this->loaders as $loader) {
@ -27,8 +29,8 @@ class Collection implements LoaderInterface {
}
/** @return LoaderInterface[] */
public function getLoaders() : array {
public function getLoaders(): array
{
return $this->loaders;
}
}
}

9
old/Loader/LoaderInterface.php

@ -0,0 +1,9 @@
<?php
namespace Spip\Autodoc\Loader;
interface LoaderInterface
{
public function getDirectories(): array;
public function load(): void;
}

2
src/Application.php

@ -1,4 +1,5 @@
<?php
/**
* autodoc : phpDocumentor pour SPIP
*/
@ -24,4 +25,3 @@ class Application extends ConsoleApplication
#$this->add(new Command\FromFile());
}
}

21
src/Checkout.php

@ -5,8 +5,8 @@ namespace Spip\Autodoc;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;
class Checkout {
class Checkout
{
/** Directory name */
private string $destination;
/** Path where we will run the checkout command */
@ -25,7 +25,8 @@ class Checkout {
$this->checkout = $this->findCommand('checkout') ?? throw new \RuntimeException('Checkout not found.');
}
public function run(string $command) {
public function run(string $command)
{
$cmd = "cd {$this->root} && {$this->checkout} $command {$this->destination} 2> /dev/null";
$this->logger->info($cmd);
exec($cmd, $res, $error);
@ -37,14 +38,16 @@ class Checkout {
return $res;
}
public function read() {
public function read()
{
return $this->run('--read');
}
/**
* Retrouver des infos du git
*/
function readGit(): Git {
public function readGit(): Git
{
// Ici, on a les bons fichiers SVN à jour
// on récupère le numéro de dernière révision
if ($res = $this->read()) {
@ -54,14 +57,15 @@ class Checkout {
$git->setCommit(substr($res[2], 2)); // -r{commit}
$git->setBranch(substr($res[3], 2)); // -b{branch}
return $git;
}
}
return new Git();
}
/**
* Obtient le chemin d'un executable sur le serveur
*/
private function findCommand(string $command) : string {
private function findCommand(string $command): string
{
static $commands = [];
if (array_key_exists($command, $commands)) {
return $commands[$command];
@ -75,5 +79,4 @@ class Checkout {
$this->logger->error("Command '$command' not found");
return $commands[$command] = '';
}
}
}

9
src/Command/FromDirectory.php

@ -40,7 +40,6 @@ class FromDirectory extends Command
protected function execute(InputInterface $input, OutputInterface $output)
{
$context = new Context($input, $output);
/** @var SymfonyStyle */
@ -68,10 +67,10 @@ class FromDirectory extends Command
{
$processor = new InterruptibleProcessor(fn (Context $context) => $context->empty('errors'));
$pipeline = (new Pipeline($processor))
->pipe(new CheckStage)
->pipe(new PackageStage)
->pipe(new PhpDocumentorConfigStage)
->pipe(new PhpDocumentorStage);
->pipe(new CheckStage())
->pipe(new PackageStage())
->pipe(new PhpDocumentorConfigStage())
->pipe(new PhpDocumentorStage());
$pipeline->process($context);
}

10
src/Command/FromGit.php

@ -80,11 +80,11 @@ class FromGit extends Command
{
$processor = new InterruptibleProcessor(fn (Context $context) => $context->empty('errors'));
$pipeline = (new Pipeline($processor))
->pipe(new CheckStage)
->pipe(new GitStage)
->pipe(new PackageStage)
->pipe(new PhpDocumentorConfigStage)
->pipe(new PhpDocumentorStage);
->pipe(new CheckStage())
->pipe(new GitStage())
->pipe(new PackageStage())
->pipe(new PhpDocumentorConfigStage())
->pipe(new PhpDocumentorStage());
$pipeline->process($context);
}

7
src/Command/FromPlugin.php

@ -6,15 +6,8 @@
namespace Spip\Autodoc\Command;
use Spip\Autodoc\Generator;
use Spip\Autodoc\Git;
use Spip\Autodoc\Loader;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* Déclaration et exécution de l'application depuis le svn d'un plugin de la zone de SPIP

11
src/Command/FromSpip.php

@ -16,7 +16,6 @@ use Spip\Autodoc\Stage\PhpDocumentorConfigStage;
use Spip\Autodoc\Stage\PhpDocumentorStage;
use Symfony\Component\Console\Input\InputOption;
/**
* Déclaration et exécution de l'application depuis le svn du core de SPIP
*/
@ -49,11 +48,11 @@ class FromSpip extends FromGit
{
$processor = new InterruptibleProcessor(fn (Context $context) => $context->empty('errors'));
$pipeline = (new Pipeline($processor))
->pipe(new CheckStage)
->pipe(new GitSpipStage)
->pipe(new PackageStage)
->pipe(new PhpDocumentorConfigStage)
->pipe(new PhpDocumentorStage);
->pipe(new CheckStage())
->pipe(new GitSpipStage())
->pipe(new PackageStage())
->pipe(new PhpDocumentorConfigStage())
->pipe(new PhpDocumentorStage());
$pipeline->process($context);
}

7
src/Command/FromZone.php

@ -6,15 +6,8 @@
namespace Spip\Autodoc\Command;
use Spip\Autodoc\Generator;
use Spip\Autodoc\Git;
use Spip\Autodoc\Loader;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* Déclaration et exécution de l'application depuis le Git de la zone de SPIP

9
src/Context.php

@ -12,13 +12,15 @@ class Context
/** @var array<mixed> */
private array $context = [];
public function __construct(InputInterface $input , OutputInterface $output) {
public function __construct(InputInterface $input, OutputInterface $output)
{
$this->set('io', new SymfonyStyle($input, $output));
$this->set('logger', new ConsoleLogger($output));
$this->init();
}
public function init(): void {
public function init(): void
{
$this->set('cwd_directory', getcwd());
$this->set('php', PHP_BINARY);
$this->set('phpdocumentor', $this->get('cwd_directory') . '/phpDocumentor.phar');
@ -63,7 +65,8 @@ class Context
return $this->context[$key];
}
public function empty(string $key): bool {
public function empty(string $key): bool
{
if (!$this->has($key)) {
return true;
}

6
src/Exception/AutodocException.php

@ -4,6 +4,6 @@ namespace Spip\Autodoc\Exception;
use Exception;
class AutodocException extends Exception {
}
class AutodocException extends Exception
{
}

6
src/Exception/ContextException.php

@ -4,6 +4,6 @@ namespace Spip\Autodoc\Exception;
use Exception;
class ContextException extends Exception {
}
class ContextException extends Exception
{
}

17
src/Git.php

@ -2,7 +2,8 @@
namespace Spip\Autodoc;
class Git {
class Git
{
private ?string $url = null;
private ?string $commit = null;
private ?string $branch = null;
@ -12,39 +13,39 @@ class Git {
$this->url = $url;
}
public function getUrl() : ?string
public function getUrl(): ?string
{
return $this->url;
}
public function setUrl($url) : self
public function setUrl($url): self
{
$this->url = $url;
return $this;
}
public function getCommit() : ?string
public function getCommit(): ?string
{
return $this->commit;
}
public function setCommit($commit) : self
public function setCommit($commit): self
{
$this->commit = $commit;
return $this;
}
public function getBranch() : ?string
public function getBranch(): ?string
{
return $this->branch;
}
public function setBranch($branch) : self
public function setBranch($branch): self
{
$this->branch = $branch;
return $this;
}
}
}

8
src/Loader/LoaderInterface.php

@ -1,8 +0,0 @@
<?php
namespace Spip\Autodoc\Loader;
interface LoaderInterface {
public function getDirectories() : array;
public function load() : void;
}

24
src/Package.php

@ -7,8 +7,8 @@ use Psr\Log\NullLogger;
use RuntimeException;
use Spip\Autodoc\Exception\AutodocException;
class Package {
class Package
{
private bool $is_spip = false;
private bool $is_plugin = false;
private string $prefix = '';
@ -30,11 +30,13 @@ class Package {
$this->analyse();
}
public function __get(string $name) {
public function __get(string $name)
{
return $this->get($name);
}
public function get(string $name) {
public function get(string $name)
{
if (!isset($this->$name)) {
throw new RuntimeException(sprintf('Property "%s" does not exists', $name));
}
@ -42,7 +44,8 @@ class Package {
return $this->$name;
}
public function set(string $name, $value): self {
public function set(string $name, $value): self
{
if (!isset($this->$name)) {
throw new RuntimeException(sprintf('Property "%s" does not exists', $name));
}
@ -51,7 +54,8 @@ class Package {
return $this;
}
public function analyse() {
public function analyse()
{
$this->is_plugin = false;
$this->is_spip = false;
if (file_exists($path_package = $this->input_directory.'/paquet.xml')) {
@ -67,7 +71,8 @@ class Package {
}
}
private function load(string $path_package) {
private function load(string $path_package)
{
if (!is_readable($path_package)) {
throw new AutodocException(sprintf('Can’t read "%s" file', $path_package));
}
@ -93,7 +98,8 @@ class Package {
}
}
private function readLangFile(string $langFile): array {
private function readLangFile(string $langFile): array
{
if (file_exists($langFile)) {
$GLOBALS['pour_autodoc'] = null;
$GLOBALS['idx_lang'] = 'pour_autodoc';
@ -103,4 +109,4 @@ class Package {
}
return [];
}
}
}

5
src/Stage/GitSpipStage.php

@ -8,6 +8,7 @@ use Spip\Autodoc\Exception\ContextException;
use Spip\Autodoc\Git;
use Symfony\Component\Filesystem\Filesystem;
class GitSpipStage extends GitStage {
class GitSpipStage extends GitStage
{
protected const CHECKOUT_TYPE = 'spip';
}
}

9
src/Stage/GitStage.php

@ -8,7 +8,8 @@ use Spip\Autodoc\Exception\ContextException;
use Spip\Autodoc\Git;
use Symfony\Component\Filesystem\Filesystem;
class GitStage implements StageInterface {
class GitStage implements StageInterface
{
protected const CHECKOUT_TYPE = 'git';
public function __invoke(Context $context): Context
@ -32,8 +33,8 @@ class GitStage implements StageInterface {
/**
* Télécharge ou met à jour la source Git
**/
private function download(Context $context) : void {
private function download(Context $context): void
{
if (!$context->has('input_directory')) {
$context->set('input_directory', $context->get('input_base_directory') . '/' . $context->get('default_prefix'));
}
@ -66,4 +67,4 @@ class GitStage implements StageInterface {
// On récupère le numéro de dernière révision, ça peut servir
$this->current = $checkout->readGit();
}
}
}

8
src/Stage/PackageStage.php

@ -39,15 +39,14 @@ class PackageStage implements StageInterface
/**
* Définir avec le titre, et une présentation (si ce n'est déjà fait).
**/
private function describe(Context $context, Package $package) {
private function describe(Context $context, Package $package)
{
if (!$context->has('title')) {
$context->set('title', $package->name ?: ucfirst($context->get('default_prefix')));
$context->get('logger')->debug('Title: ' . $context->get('title'));
}
if (!$context->has('presentation')) {
$rev = "";
if ($context->has('git_current')) {
/** @var Git */
@ -61,7 +60,7 @@ class PackageStage implements StageInterface
}
$presentation = 'Cette documentation est issue du code source PHP ';
$presentation .= match(true) {
$presentation .= match (true) {
$package->is_spip => 'de SPIP '.$package->version.$rev.'.',
$package->is_plugin => 'du plugin « '.$package->name.' », version '.$package->version.$rev.'.',
default => 'de « '.$context->get('title').' »'.$rev.'.',
@ -83,5 +82,4 @@ class PackageStage implements StageInterface
$context->get('logger')->debug("Presentation: \n". rtrim(str_replace('&#13;&#10;', "\n", $presentation)));
}
}
}

1
src/Stage/StageInterface.php

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
namespace Spip\Autodoc\Stage;

Loading…
Cancel
Save