Skip to content

Commit

Permalink
Down to 16 phpstan errors
Browse files Browse the repository at this point in the history
  • Loading branch information
DepkaCZ committed Jul 16, 2018
1 parent a648582 commit 26ef015
Show file tree
Hide file tree
Showing 13 changed files with 36 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/Annotations/AnnotationsRuleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(Reader $reader)
}

/**
* @param ReflectionClass|ReflectionMethod|ReflectionProperty $reflection
* @param Reflector $reflection
*
* @return RuleInterface[]
*/
Expand Down
4 changes: 1 addition & 3 deletions src/Application/VerifierControlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ public function redirectVerified($code, $destination = null, $parameters = []):
$parameters = is_array($destination) ? $destination : array_slice(func_get_args(), 1);
$destination = $code;
$code = null;
} elseif (!is_array($parameters)) {
$parameters = array_slice(func_get_args(), 2);
}

/** @var Presenter $presenter */
Expand Down Expand Up @@ -88,7 +86,7 @@ protected function createComponent($name): ?IComponent
{
$method = 'createComponent'.ucfirst($name);
if (method_exists($this, $method)) {
$this->checkRequirements($this->getReflection()->getMethod($method));
$this->checkRequirements(self::getReflection()->getMethod($method));
}

return parent::createComponent($name);
Expand Down
13 changes: 10 additions & 3 deletions src/Application/VerifierPresenterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function checkRequirements($reflection): void
{
$rules = $this->verifier->getRules($reflection);

if ($rules && $reflection instanceof ReflectionMethod && substr($reflection->getName(), 0, 6) === 'render') {
if ((bool) $rules && $reflection instanceof ReflectionMethod && substr($reflection->getName(), 0, 6) === 'render') {
throw new NotSupportedException('Rules for render methods are not supported. Define the rules for action method instead.');
}

Expand All @@ -56,8 +56,15 @@ public function getVerifier(): Verifier

/**
* Ensures that the action method exists.
*
* @param string $method
* @param array $parameters
*
* @throws BadRequestException
*
* @return bool
*/
protected function tryCall($method, array $parameters): bool
protected function tryCall(string $method, array $parameters): bool
{
$called = parent::tryCall($method, $parameters);
if (!$called && substr($method, 0, 6) === 'action') {
Expand All @@ -81,7 +88,7 @@ public function createRequest($component, $destination, array $parameters, $mode
/**
* Calls onStartup event which is used to verify presenter properties.
*/
public function startup()
public function startup(): void
{
parent::startup();
$this->onStartup();
Expand Down
4 changes: 2 additions & 2 deletions src/DI/VerifierExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function loadConfiguration(): void
]
);

if ($this->getExtension(AnnotationsExtension::class, false)) {
if ((bool) $this->getExtension(AnnotationsExtension::class, false)) {
$builder->addDefinition($this->prefix('annotationsRuleProvider'))
->setType(RuleProviderInterface::class)
->setFactory(AnnotationsRuleProvider::class)
Expand Down Expand Up @@ -126,7 +126,7 @@ private function getExtension(string $class, bool $need = true): ?CompilerExtens
{
$extensions = $this->compiler->getExtensions($class);

if (!$extensions) {
if (!(bool) $extensions) {
if (!$need) {
return null;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Latte/VerifierMacros.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ public static function install(Compiler $compiler): void
null,
function (MacroNode $node, PhpWriter $writer) {
$word = $node->tokenizer->fetchWord();
if ($word) {
if ((bool) $word) {
$link = '$this->global->uiControl->link('.$writer->formatWord($word).', %node.array?)';
} else {
$node->modifiers .= '|safeurl';
$link = '$_verifiedLink';
}

return ' ?> href="<?php '.$writer->using($node)->write('echo %escape(%modify('.$link.'))').' ?>"<?php ';
return ' ?> href="<?php '.PhpWriter::using($node)->write('echo %escape(%modify('.$link.'))').' ?>"<?php ';
}
);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Verifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public function isComponentVerified(string $name, Request $request, Component $p
if ($reflection->hasMethod($method)) {
$factory = $reflection->getMethod($method);
try {
$this->checkReflection($factory, $request, $parent->getParent() ? $parent->getUniqueId() : null);
$this->checkReflection($factory, $request, (bool) $parent->getParent() ? $parent->getUniqueId() : null);
} catch (VerificationException $e) {
return false;
}
Expand All @@ -190,11 +190,11 @@ public function isComponentVerified(string $name, Request $request, Component $p
public function verifyProperties(Request $request, Component $component): void
{
$reflection = new ReflectionClass($component);
$id = $component->getParent() ? $component->getUniqueId() : null;
$id = (bool) $component->getParent() ? $component->getUniqueId() : null;

foreach ($reflection->getProperties(ReflectionProperty::IS_PUBLIC) as $property) {
$rules = $this->getRules($property);
if (!$rules) {
if (!(bool) $rules) {
continue;
}

Expand Down
4 changes: 3 additions & 1 deletion tests/functional/src/Classes/BlockControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@ public function render(): void

/**
* @Enabled( "$parameter" )
*
* @param string $parameter
*/
public function handleSignal($parameter): void
public function handleSignal(string $parameter): void
{
$this->template->message = 'Signal called!';
}
Expand Down
4 changes: 3 additions & 1 deletion tests/functional/src/Classes/ChildControl.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ class ChildControl extends Control

/**
* @Enabled( "$parameter" )
*
* @param string $parameter
*/
public function handleSignal1($parameter): void
public function handleSignal1(string $parameter): void
{
$this->redirectVerified('signal2!');
}
Expand Down
1 change: 1 addition & 0 deletions tests/functional/src/Classes/Enabled.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
*/
class Enabled extends SecurityRule
{
/** @var string|bool */
public $value;
}
2 changes: 1 addition & 1 deletion tests/functional/src/Classes/EnabledRuleHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function checkRule(RuleInterface $rule, Request $request, ?string $compon

if (is_string($rule->value)) {
$parameters = $request->getParameters();
$parameter = ($component ? $component.'-' : '').ltrim($rule->value, '$');
$parameter = ((bool) $component ? $component.'-' : '').ltrim($rule->value, '$');
$enabled = isset($parameters[$parameter]) && (bool) $parameters[$parameter];
} else {
$enabled = $rule->value;
Expand Down
14 changes: 7 additions & 7 deletions tests/functional/src/RuleHandlersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testEitherFirst(): void
]
);

$this->assertTrue($this->verifier->isLinkVerified($request, new TestPresenter()));
self::assertTrue($this->verifier->isLinkVerified($request, new TestPresenter()));
}

public function testEitherSecond(): void
Expand All @@ -54,7 +54,7 @@ public function testEitherSecond(): void
]
);

$this->assertTrue($this->verifier->isLinkVerified($request, new TestPresenter()));
self::assertTrue($this->verifier->isLinkVerified($request, new TestPresenter()));
}

public function testEitherFalse(): void
Expand All @@ -67,7 +67,7 @@ public function testEitherFalse(): void
]
);

$this->assertFalse($this->verifier->isLinkVerified($request, new TestPresenter()));
self::assertFalse($this->verifier->isLinkVerified($request, new TestPresenter()));
}

public function testEitherInner(): void
Expand All @@ -80,7 +80,7 @@ public function testEitherInner(): void
]
);

$this->assertFalse($this->verifier->isLinkVerified($request, new TestPresenter()));
self::assertFalse($this->verifier->isLinkVerified($request, new TestPresenter()));
}

public function testAllTrue(): void
Expand All @@ -93,7 +93,7 @@ public function testAllTrue(): void
]
);

$this->assertTrue($this->verifier->isLinkVerified($request, new TestPresenter()));
self::assertTrue($this->verifier->isLinkVerified($request, new TestPresenter()));
}

public function testAllFalse(): void
Expand All @@ -106,7 +106,7 @@ public function testAllFalse(): void
]
);

$this->assertFalse($this->verifier->isLinkVerified($request, new TestPresenter()));
self::assertFalse($this->verifier->isLinkVerified($request, new TestPresenter()));
}

public function testAllInner(): void
Expand All @@ -119,6 +119,6 @@ public function testAllInner(): void
]
);

$this->assertTrue($this->verifier->isLinkVerified($request, new TestPresenter()));
self::assertTrue($this->verifier->isLinkVerified($request, new TestPresenter()));
}
}
1 change: 1 addition & 0 deletions tests/unit/src/Classes/TestPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
class TestPresenter extends Presenter
{
/**
* @var string
* @TestRule
*/
public $property;
Expand Down
2 changes: 1 addition & 1 deletion tests/unit/src/VerifierTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public function testInvalidRule(): void

try {
$this->verifier->isLinkVerified($request, $component);
$this->fail();
self::fail();
} catch (UnexpectedTypeException $e) {
}

Expand Down

0 comments on commit 26ef015

Please sign in to comment.