diff --git a/AbortStageException.php b/AbortStageException.php index f793e2b..a2374d0 100644 --- a/AbortStageException.php +++ b/AbortStageException.php @@ -1,4 +1,7 @@ container = $container; if (!empty($path)) { @@ -55,10 +82,9 @@ function __construct(ContainerInterface $container, $path) /** * Load the stage definitions from $path * - * @param string $path including filename, e.g. my/full/path/to/my/stages.yml * @throws FileLoaderLoadException */ - public function loadStagesFromYaml($path) + public function loadStagesFromYaml(string $path): void { if (!file_exists($path)) { throw new FileLoaderLoadException('Stage definition file cannot be found.'); @@ -67,12 +93,14 @@ public function loadStagesFromYaml($path) if ($pathInfo['extension'] !== 'yml') { throw new FileLoaderLoadException('Stage definition file must include .yml extension.'); } - $this->stages = []; // empty the stages - if (!isset($this->YamlFileLoader)) { - $this->YamlFileLoader = new YamlFileLoader(new FileLocator($pathInfo['dirname'])); + + // empty the stages + $this->stagesByName = []; + if (!isset($this->yamlFileLoader)) { + $this->yamlFileLoader = new YamlFileLoader(new FileLocator($pathInfo['dirname'])); } - $this->YamlFileLoader->load($pathInfo['basename']); - $stages = $this->YamlFileLoader->getContent(); + $this->yamlFileLoader->load($pathInfo['basename']); + $stages = $this->yamlFileLoader->getContent(); $stages = $stages['stages']; foreach ($stages as $key => $stageArray) { $this->stagesByName[$key] = $stageArray['class']; @@ -85,16 +113,14 @@ public function loadStagesFromYaml($path) /** * Get the stage that is the first necessary stage - * - * @param $name - * @return StageInterface */ - public function getCurrentStage($name) + public function getCurrentStage(string $name): StageInterface { // compute the stageClass from Request parameter $stageClass = $this->getStageClassName($name); // loop each stage until finds the first that is necessary + do { $useCurrentStage = false; /** @var StageInterface $currentStage */ @@ -113,38 +139,31 @@ public function getCurrentStage($name) } else { $currentStage = $this->getNextStage(); } - } while ($useCurrentStage == false); + } while (false === $useCurrentStage); return $currentStage; } /** * Get an instance of the previous stage - * - * @return StageInterface */ - public function getPreviousStage() + public function getPreviousStage(): StageInterface { return $this->getSequentialStage('prev'); } /** * Get an instance of the next stage - * - * @return StageInterface */ - public function getNextStage() + public function getNextStage(): StageInterface { return $this->getSequentialStage('next'); } /** - * get either previous or next stage - * - * @param $direction (prev|next) - * @return StageInterface|null + * Get either previous or next stage */ - private function getSequentialStage($direction) + private function getSequentialStage(string $direction): ?StageInterface { $dir = in_array($direction, ['prev', 'next']) ? $direction : 'next'; ksort($this->stageOrder); @@ -154,7 +173,6 @@ private function getSequentialStage($direction) } $key = $dir($this->stageOrder); if (null !== $key && false !== $key) { - return $this->getStageInstance($this->stagesByName[$key]); } @@ -163,61 +181,48 @@ private function getSequentialStage($direction) /** * Factory class to instantiate a StageClass - * - * @param $stageClass - * @return StageInterface */ - private function getStageInstance($stageClass) + private function getStageInstance(string $stageClass): StageInterface { if (!class_exists($stageClass)) { throw new RuntimeException('Error: Could not find requested stage class.'); } - if (in_array("Zikula\\Component\\Wizard\\InjectContainerInterface", class_implements($stageClass))) { - + if (in_array("Zikula\\Component\\Wizard\\InjectContainerInterface", class_implements($stageClass), true)) { return new $stageClass($this->container); - } else { - - return new $stageClass(); } + + return new $stageClass(); } /** * Has the wizard been halted? - * - * @return bool */ - public function isHalted() + public function isHalted(): bool { - return (!empty($this->warning)); + return !empty($this->warning); } /** - * get any warning currently set - * - * @return string + * Get any warning currently set */ - public function getWarning() + public function getWarning(): string { - return "WARNING: The Wizard was halted for the following reason. This must be corrected before you can continue. " . $this->warning; + return 'WARNING: The Wizard was halted for the following reason. This must be corrected before you can continue. ' . $this->warning; } /** * Match the stage and return the stage classname or default. * - * @param $name - * @return string - * @throws \InvalidArgumentException + * @throws InvalidArgumentException */ - private function getStageClassName($name) + private function getStageClassName(string $name): string { if (!empty($this->stagesByName[$name])) { - return $this->stagesByName[$name]; } if (!empty($this->defaultStage) && !empty($this->stagesByName[$this->defaultStage])) { - return $this->stagesByName[$this->defaultStage]; } - throw new \InvalidArgumentException('The request stage could not be found and there is no default stage defined.'); + throw new InvalidArgumentException('The request stage could not be found and there is no default stage defined.'); } } diff --git a/WizardCompleteInterface.php b/WizardCompleteInterface.php index 92a1e65..5f2b92e 100644 --- a/WizardCompleteInterface.php +++ b/WizardCompleteInterface.php @@ -1,4 +1,7 @@ content; } @@ -56,13 +51,9 @@ public function getContent() /** * Loads a YAML file. * - * @param string $file - * - * @return array The file content - * * @throws InvalidArgumentException when the given file is not a local file or when it does not exist */ - private function loadFile($file) + private function loadFile(string $file): array { if (!stream_is_local($file)) { throw new InvalidArgumentException(sprintf('This is not a local file "%s".', $file)); @@ -82,14 +73,12 @@ private function loadFile($file) /** * Validates a YAML file. * - * @param mixed $content - * @param string $file - * + * @param mixed $content * @return array * * @throws InvalidArgumentException When service file is not valid */ - private function validate($content, $file) + private function validate($content, string $file): array { if (null === $content) { return $content; @@ -99,10 +88,8 @@ private function validate($content, $file) throw new InvalidArgumentException(__f('The yaml file "%s" is not valid. It should contain an array. Check your YAML syntax.', $file)); } - if (isset($content['stages'])) { - if (!is_array($content['stages'])) { - throw new InvalidArgumentException(__f('The "stages" key should contain an array in %s. Check your YAML syntax.', $file)); - } + if (isset($content['stages']) && !is_array($content['stages'])) { + throw new InvalidArgumentException(__f('The "stages" key should contain an array in %s. Check your YAML syntax.', $file)); } return $content;