Skip to content

Commit 394fd63

Browse files
committed
CI: fixed coding style, added needed return type hints
1 parent 57c9eaf commit 394fd63

22 files changed

+138
-172
lines changed

ruleset.xml

+19
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
11
<?xml version="1.0"?>
22
<ruleset name="Kdyby/Console">
33
<rule ref="vendor/kdyby/coding-standard/ruleset.xml"/>
4+
<rule ref="Consistence.Exceptions.ExceptionDeclaration.NotEndingWithException">
5+
<exclude-pattern>src/FatalThrowableError.php</exclude-pattern>
6+
</rule>
7+
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly.ReferencedGeneralException">
8+
<exclude-pattern>src/FatalThrowableError.php</exclude-pattern>
9+
</rule>
10+
<rule ref="SlevomatCodingStandard.Functions.StaticClosure.ClosureNotStatic">
11+
<exclude-pattern>tests/KdybyTests/Console/ApplicationTest.phpt</exclude-pattern>
12+
</rule>
13+
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint">
14+
<exclude-pattern>src/Application.php</exclude-pattern>
15+
<exclude-pattern>src/StringOutput.php</exclude-pattern>
16+
</rule>
17+
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint">
18+
<exclude-pattern>src/ContainerHelper</exclude-pattern>
19+
</rule>
20+
<rule ref="SlevomatCodingStandard.Variables.UnusedVariable.UnusedVariable">
21+
<exclude-pattern>src/DI/ConsoleExtension.php</exclude-pattern>
22+
</rule>
423
</ruleset>

src/Application.php

+19-19
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Nette\DI\Container;
1717
use Symfony\Component\Console\Command\Command;
1818
use Symfony\Component\Console\Input\ArgvInput;
19+
use Symfony\Component\Console\Input\InputDefinition;
1920
use Symfony\Component\Console\Input\InputInterface;
2021
use Symfony\Component\Console\Input\InputOption;
2122
use Symfony\Component\Console\Output\ConsoleOutput;
@@ -28,9 +29,9 @@ class Application extends \Symfony\Component\Console\Application
2829

2930
use \Kdyby\StrictObjects\Scream;
3031

31-
const CLI_SAPI = 'cli';
32-
const INPUT_ERROR_EXIT_CODE = 253;
33-
const INVALID_APP_MODE_EXIT_CODE = 252;
32+
public const CLI_SAPI = 'cli';
33+
public const INPUT_ERROR_EXIT_CODE = 253;
34+
public const INVALID_APP_MODE_EXIT_CODE = 252;
3435

3536
/**
3637
* @var string[]
@@ -46,11 +47,7 @@ class Application extends \Symfony\Component\Console\Application
4647
*/
4748
private $serviceLocator;
4849

49-
/**
50-
* @param string $name
51-
* @param string $version
52-
*/
53-
public function __construct($name = 'Nette Framework', $version = 'UNKNOWN')
50+
public function __construct(string $name = 'Nette Framework', string $version = 'UNKNOWN')
5451
{
5552
if ( ! $version && \class_exists(\Nette\DI\Definitions\ServiceDefinition::class)) {
5653
$version = \Kdyby\Console\DI\ConsoleExtension::NETTE_VERSION_30;
@@ -65,18 +62,21 @@ public function __construct($name = 'Nette Framework', $version = 'UNKNOWN')
6562
$this->setAutoExit(FALSE);
6663
}
6764

68-
public function injectServiceLocator(Container $sl)
65+
public function injectServiceLocator(Container $sl): void
6966
{
7067
$this->serviceLocator = $sl;
7168
}
7269

73-
public function find($name)
70+
/**
71+
* @param string $name
72+
*/
73+
public function find($name): Command
7474
{
7575
try {
7676
return parent::find($name);
7777

7878
} catch (\InvalidArgumentException $e) {
79-
throw new Exception\UnknownCommandException($e->getMessage(), $e->getCode(), $e);
79+
throw new \Kdyby\Console\Exception\UnknownCommandException($e->getMessage(), $e->getCode(), $e);
8080
}
8181
}
8282

@@ -86,15 +86,15 @@ public function find($name)
8686
* @return int
8787
* @throws \Exception
8888
*/
89-
public function run(InputInterface $input = NULL, OutputInterface $output = NULL)
89+
public function run(?InputInterface $input = NULL, ?OutputInterface $output = NULL): int
9090
{
9191
$input = $input ?: new ArgvInput();
9292
$output = $output ?: new ConsoleOutput();
9393

9494
if ($input->hasParameterOption('--debug-mode')) {
9595
if ($input->hasParameterOption(['--debug-mode=no', '--debug-mode=off', '--debug-mode=false', '--debug-mode=0'])) {
9696
if ($this->serviceLocator->parameters['debugMode']) {
97-
$this->renderException(new Exception\InvalidApplicationModeException(
97+
$this->renderException(new \Kdyby\Console\Exception\InvalidApplicationModeException(
9898
'The app is running in debug mode. You have to use Kdyby\Console\DI\BootstrapHelper in app/bootstrap.php, ' .
9999
'Kdyby\Console cannot switch already running app to production mode.'
100100
), $output);
@@ -104,7 +104,7 @@ public function run(InputInterface $input = NULL, OutputInterface $output = NULL
104104

105105
} else {
106106
if (!$this->serviceLocator->parameters['debugMode']) {
107-
$this->renderException(new Exception\InvalidApplicationModeException(
107+
$this->renderException(new \Kdyby\Console\Exception\InvalidApplicationModeException(
108108
'The app is running in production mode. You have to use Kdyby\Console\DI\BootstrapHelper in app/bootstrap.php, ' .
109109
'Kdyby\Console cannot switch already running app to debug mode.'
110110
), $output);
@@ -121,9 +121,9 @@ public function run(InputInterface $input = NULL, OutputInterface $output = NULL
121121
try {
122122
return parent::run($input, $output);
123123

124-
} catch (Exception\UnknownCommandException $e) {
124+
} catch (\Kdyby\Console\Exception\UnknownCommandException $e) {
125125
$this->renderException($e->getPrevious(), $output);
126-
list($message) = explode("\n", $e->getMessage());
126+
[$message] = explode("\n", $e->getMessage());
127127
Debugger::log($message, Debugger::ERROR);
128128

129129
return self::INPUT_ERROR_EXIT_CODE;
@@ -156,7 +156,7 @@ public function run(InputInterface $input = NULL, OutputInterface $output = NULL
156156
* @param \Exception|\Throwable $e
157157
* @param \Symfony\Component\Console\Output\OutputInterface|NULL $output
158158
*/
159-
public function handleException($e, OutputInterface $output = NULL)
159+
public function handleException($e, ?OutputInterface $output = NULL): void
160160
{
161161
$output = $output ?: new ConsoleOutput();
162162
if ($e instanceof \Exception) {
@@ -181,7 +181,7 @@ public function handleException($e, OutputInterface $output = NULL)
181181
}
182182
}
183183

184-
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
184+
protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output): int
185185
{
186186
if ($this->serviceLocator) {
187187
$this->serviceLocator->callInjects($command);
@@ -190,7 +190,7 @@ protected function doRunCommand(Command $command, InputInterface $input, OutputI
190190
return parent::doRunCommand($command, $input, $output);
191191
}
192192

193-
protected function getDefaultInputDefinition()
193+
protected function getDefaultInputDefinition(): InputDefinition
194194
{
195195
$definition = parent::getDefaultInputDefinition();
196196
$definition->addOption(new InputOption('--debug-mode', NULL, InputOption::VALUE_OPTIONAL, 'Run the application in debug mode?'));

src/CliPresenter.php

+6-10
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@
2525
class CliPresenter extends \Nette\Application\UI\Presenter
2626
{
2727

28-
const NAME = 'Kdyby:Cli';
28+
public const NAME = 'Kdyby:Cli';
2929

3030
/**
3131
* @var string
3232
*/
33-
public $name = \KdybyModule\CliPresenter::NAME;
33+
public $name = self::NAME;
3434

3535
/**
3636
* @var \Kdyby\Console\Application|NULL
@@ -42,34 +42,30 @@ class CliPresenter extends \Nette\Application\UI\Presenter
4242
*/
4343
private $application;
4444

45-
protected function startup()
45+
protected function startup(): void
4646
{
4747
parent::startup();
4848
$this->autoCanonicalize = FALSE;
4949
}
5050

51-
/**
52-
* @param \Kdyby\Console\Application $console
53-
* @param \Nette\Application\Application $application
54-
*/
5551
public function injectConsole(
5652
ConsoleApplication $console,
5753
NetteApplication $application
58-
)
54+
): void
5955
{
6056
$this->console = $console;
6157
$this->application = $application;
6258
}
6359

64-
public function actionDefault()
60+
public function actionDefault(): void
6561
{
6662
if ($this->console === NULL || $this->application === NULL) {
6763
throw new \Kdyby\Console\Exception\InvalidStateException('Before running the presenter, call injectConsole() with required dependencies.');
6864
}
6965

7066
$request = $this->getRequest();
7167
if ($request === NULL) {
72-
throw new \Kdyby\Console\Exception\InvalidStateException(sprintf('Do not call %s directly, use %s::run()', __FUNCTION__, __CLASS__));
68+
throw new \Kdyby\Console\Exception\InvalidStateException(sprintf('Do not call %s directly, use %s::run()', __FUNCTION__, self::class));
7369
}
7470

7571
$params = $request->getParameters();

src/CliResponse.php

+3-9
Original file line numberDiff line numberDiff line change
@@ -31,26 +31,20 @@ class CliResponse implements \Nette\Application\IResponse
3131
*/
3232
private $application;
3333

34-
/**
35-
* @param int $exitCode
36-
*/
37-
public function __construct($exitCode)
34+
public function __construct(int $exitCode)
3835
{
3936
$this->exitCode = $exitCode;
4037
}
4138

4239
/**
4340
* @internal
4441
*/
45-
public function injectApplication(NetteApplication $application)
42+
public function injectApplication(NetteApplication $application): void
4643
{
4744
$this->application = $application;
4845
}
4946

50-
/**
51-
* @return int
52-
*/
53-
public function getExitCode()
47+
public function getExitCode(): int
5448
{
5549
return $this->exitCode;
5650
}

src/CliRouter.php

+7-9
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,20 @@ class CliRouter implements \Nette\Routing\Router
3737
*/
3838
private $output;
3939

40-
/**
41-
* @param \Symfony\Component\Console\Output\OutputInterface $output
42-
*/
43-
public function setOutput(OutputInterface $output)
40+
public function setOutput(OutputInterface $output): void
4441
{
4542
$this->output = $output;
4643
}
4744

48-
/**
49-
* @param \Symfony\Component\Console\Input\InputInterface $input
50-
*/
51-
public function setInput(InputInterface $input)
45+
public function setInput(InputInterface $input): void
5246
{
5347
$this->input = $input;
5448
}
5549

5650
/**
5751
* Maps HTTP request to a Request object.
52+
*
53+
* @return mixed[]
5854
*/
5955
public function match(\Nette\Http\IRequest $httpRequest): ?array
6056
{
@@ -87,8 +83,10 @@ public function match(\Nette\Http\IRequest $httpRequest): ?array
8783

8884
/**
8985
* Constructs absolute URL from Request object.
86+
*
87+
* @param mixed[] $params
9088
*/
91-
public function constructUrl(array $params, \Nette\Http\UrlScript $refUrl) : ?string
89+
public function constructUrl(array $params, \Nette\Http\UrlScript $refUrl): ?string
9290
{
9391
return NULL;
9492
}

src/ContainerHelper.php

+7-21
Original file line numberDiff line numberDiff line change
@@ -24,28 +24,20 @@ class ContainerHelper extends \Symfony\Component\Console\Helper\Helper
2424
*/
2525
private $container;
2626

27-
/**
28-
* @param \Nette\DI\Container $dic
29-
*/
3027
public function __construct(DIContainer $dic)
3128
{
3229
$this->container = $dic;
3330
}
3431

35-
/**
36-
* @param string $key
37-
* @return bool
38-
*/
39-
public function hasParameter($key)
32+
public function hasParameter(string $key): bool
4033
{
4134
return isset($this->container->parameters[$key]);
4235
}
4336

4437
/**
45-
* @param string $key
4638
* @return mixed
4739
*/
48-
public function getParameter($key)
40+
public function getParameter(string $key)
4941
{
5042
if (!$this->hasParameter($key)) {
5143
return NULL;
@@ -55,36 +47,30 @@ public function getParameter($key)
5547
}
5648

5749
/**
58-
* @return array
50+
* @return mixed[]
5951
*/
60-
public function getParameters()
52+
public function getParameters(): array
6153
{
6254
return $this->container->parameters;
6355
}
6456

65-
/**
66-
* @return \Nette\DI\Container
67-
*/
68-
public function getContainer()
57+
public function getContainer(): DIContainer
6958
{
7059
return $this->container;
7160
}
7261

7362
/**
74-
* @param string $type
7563
* @return object
7664
*/
77-
public function getByType($type)
65+
public function getByType(string $type)
7866
{
7967
return $this->container->getByType($type);
8068
}
8169

8270
/**
8371
* Returns the canonical name of this helper.
84-
*
85-
* @return string The canonical name
8672
*/
87-
public function getName()
73+
public function getName(): string
8874
{
8975
return 'container';
9076
}

src/DI/BootstrapHelper.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class BootstrapHelper
4545
* @param \Nette\Configurator $configurator
4646
* @return bool has the debug mode been modified?
4747
*/
48-
public static function setupMode(Configurator $configurator)
48+
public static function setupMode(Configurator $configurator): bool
4949
{
5050
if (PHP_SAPI !== Application::CLI_SAPI) {
5151
return FALSE;
@@ -61,10 +61,10 @@ public static function setupMode(Configurator $configurator)
6161
$configurator->setDebugMode(FALSE);
6262
return TRUE;
6363

64-
} else {
65-
$configurator->setDebugMode(TRUE);
66-
return TRUE;
6764
}
65+
66+
$configurator->setDebugMode(TRUE);
67+
return TRUE;
6868
}
6969

7070
}

0 commit comments

Comments
 (0)