Skip to content
This repository has been archived by the owner on Apr 2, 2021. It is now read-only.

Commit

Permalink
Bugfix: Added forgotten render call on error block in command router
Browse files Browse the repository at this point in the history
  • Loading branch information
mfrankruijter committed May 2, 2020
1 parent f0cf3f7 commit e2d0aee
Show file tree
Hide file tree
Showing 25 changed files with 73 additions and 27 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 1.0.3 - 2020-05-02
### Fixed
- Forgotten render call on error block.

## 1.0.2 - 2020-04-09
### Changed
- Changed packages to GrizzIT variations.
Expand All @@ -17,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Created the initial implementation of the command package.

# Versions
- [1.0.2 > Unreleased](https://github.com/ulrack/command/compare/1.0.1...HEAD)
- [1.0.3 > Unreleased](https://github.com/ulrack/command/compare/1.0.3...HEAD)
- [1.0.2 > 1.0.3](https://github.com/ulrack/command/compare/1.0.2...1.0.3)
- [1.0.1 > 1.0.2](https://github.com/ulrack/command/compare/1.0.1...1.0.2)
- [1.0.0 > 1.0.1](https://github.com/ulrack/command/compare/1.0.0...1.0.1)
3 changes: 1 addition & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
<arg name="colors" />
<arg value="s" />

<!-- Use the PSR2 Standard-->
<rule ref="PSR2" />
<rule ref="PSR12" />
</ruleset>
1 change: 1 addition & 0 deletions src/Command/HelpCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions src/Command/ListCommandsCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions src/Common/Command/CommandInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions src/Common/Command/InputInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions src/Common/Command/OutputInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions src/Common/Dao/CommandConfigurationInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions src/Common/Factory/InputFactoryInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions src/Common/Router/RouterInterface.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
25 changes: 17 additions & 8 deletions src/Component/Command/Input.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down Expand Up @@ -83,13 +84,17 @@ public function hasParameter(string $parameter): bool
}

if ($this->commandConfiguration !== null) {
foreach ($this->commandConfiguration
->getParameters() as $parameterInput) {
foreach (
$this->commandConfiguration
->getParameters() as $parameterInput
) {
$long = $parameterInput['long'] ?? '';
$short = $parameterInput['short'] ?? '';
if ($long === $parameter || $short === $parameter) {
if (array_key_exists($long, $this->parameters)
|| array_key_exists($short, $this->parameters)) {
if (
array_key_exists($long, $this->parameters)
|| array_key_exists($short, $this->parameters)
) {
return true;
}
}
Expand Down Expand Up @@ -157,10 +162,14 @@ public function isSetFlag(string $flag): bool

if ($this->commandConfiguration !== null) {
foreach ($this->commandConfiguration->getFlags() as $configFlag) {
if ($configFlag['long'] === $flag
|| $configFlag['short'] === $flag) {
if (in_array($configFlag['long'], $this->flags)
|| in_array($configFlag['short'], $this->flags)) {
if (
$configFlag['long'] === $flag
|| $configFlag['short'] === $flag
) {
if (
in_array($configFlag['long'], $this->flags)
|| in_array($configFlag['short'], $this->flags)
) {
return true;
}
}
Expand Down
1 change: 1 addition & 0 deletions src/Component/Command/Output.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
41 changes: 26 additions & 15 deletions src/Component/Router/CommandRouter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down Expand Up @@ -121,10 +122,12 @@ public function __invoke(InputInterface $input): int

if ($serviceKey !== '') {
try {
foreach ($this->getMissingParameters(
$input,
$command
) as $key => $value) {
foreach (
$this->getMissingParameters(
$input,
$command
) as $key => $value
) {
$input->setParameter($key, $value);
}
} catch (MisconfiguredCommandException $exception) {
Expand Down Expand Up @@ -159,7 +162,7 @@ public function __invoke(InputInterface $input): int
$this->errorElementFactory->createBlock(
$exception->getMessage(),
'error-block'
);
)->render();

$code = $exception->getCode();

Expand Down Expand Up @@ -210,24 +213,32 @@ private function getMissingParameters(
$missing = false;
$this->formGenerator->init(
'Missing parameters',
'The following parameters were required and missing. '.
'The following parameters were required and missing. ' .
'Please fill them in before execution procceeds.'
);

foreach ($configuration->getParameters() as $parameter) {
if (isset($parameter['required'])
&& $parameter['required']) {
if (!$input->hasParameter(
$parameter['long'] ?? $parameter['short']
)) {
if (
isset($parameter['required'])
&& $parameter['required']
) {
if (
!$input->hasParameter(
$parameter['long'] ?? $parameter['short']
)
) {
$missing = true;
if (isset($parameter['hidden'])
&& $parameter['hidden']) {
if (
isset($parameter['hidden'])
&& $parameter['hidden']
) {
$this->createHiddenField($parameter);

continue;
} elseif (isset($parameter['options'])
&& is_array($parameter['options'])) {
} elseif (
isset($parameter['options'])
&& is_array($parameter['options'])
) {
$this->createAutocompletingField($parameter);

continue;
Expand Down
1 change: 1 addition & 0 deletions src/Dao/CommandConfiguration.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions src/Exception/CommandCanNotExecuteException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions src/Exception/CommandNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions src/Exception/MisconfiguredCommandException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
4 changes: 3 additions & 1 deletion src/Factory/InputFactory.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down Expand Up @@ -67,7 +68,8 @@ private static function prepareArguments(array $arguments): array

// No subsequent value starting without a "-"
// It must be a flag
if (empty($arguments[0])
if (
empty($arguments[0])
|| substr($arguments[0], 0, 1) === '-'
) {
$flags[] = ltrim($argument, '-');
Expand Down
1 change: 1 addition & 0 deletions tests/Command/HelpCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions tests/Command/ListCommandsCommandTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions tests/Component/Command/InputTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions tests/Component/Command/OutputTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions tests/Component/Router/CommandRouterTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions tests/Dao/CommandConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down
1 change: 1 addition & 0 deletions tests/Factory/InputFactoryTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Copyright (C) GrizzIT, Inc. All rights reserved.
* See LICENSE for license details.
Expand Down

0 comments on commit e2d0aee

Please sign in to comment.