Skip to content

Commit

Permalink
Implemented requested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
DepkaCZ committed Jul 16, 2018
1 parent 11c1e68 commit bcbd068
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 24 deletions.
2 changes: 0 additions & 2 deletions src/Annotations/AnnotationsRuleProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public function __construct(Reader $reader)
}

/**
* @param Reflector $reflection
*
* @return RuleInterface[]
*/
public function getRules(Reflector $reflection): array
Expand Down
4 changes: 3 additions & 1 deletion src/Application/VerifierControlTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function checkRequirements($reflection): void
*
* @param int|string $code
* @param string|array $destination
* @param mixed[] $parameters
* @param mixed $parameters
*/
public function redirectVerified($code, $destination = null, $parameters = []): void
{
Expand All @@ -43,6 +43,8 @@ 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
7 changes: 0 additions & 7 deletions src/Application/VerifierPresenterTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,6 @@ 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
{
Expand Down
8 changes: 3 additions & 5 deletions src/Verifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public function __construct(RuleProviderInterface $ruleProvider, callable $handl
/**
* Returns rules that are required for given reflection.
*
* @param ReflectionClass|ReflectionMethod|ReflectionProperty $reflection
*
* @return RuleInterface[]
*/
public function getRules(Reflector $reflection): array
Expand Down Expand Up @@ -175,7 +173,7 @@ public function isComponentVerified(string $name, Request $request, Component $p
if ($reflection->hasMethod($method)) {
$factory = $reflection->getMethod($method);
try {
$this->checkReflection($factory, $request, (bool) $parent->getParent() ? $parent->getUniqueId() : null);
$this->checkReflection($factory, $request, $parent->getParent() !== null ? $parent->getUniqueId() : null);
} catch (VerificationException $e) {
return false;
}
Expand All @@ -190,11 +188,11 @@ public function isComponentVerified(string $name, Request $request, Component $p
public function verifyProperties(Request $request, Component $component): void
{
$reflection = new ReflectionClass($component);
$id = (bool) $component->getParent() ? $component->getUniqueId() : null;
$id = $component->getParent() !== null ? $component->getUniqueId() : null;

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

Expand Down
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 = ($component !== null ? $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()));
}
}
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 bcbd068

Please sign in to comment.