Skip to content

Commit

Permalink
Merge pull request #2 from Stillat/analysis-WNP4ZV
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
JohnathonKoster authored Oct 24, 2021
2 parents 029b2a7 + 6720e1a commit 7308fb4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
28 changes: 14 additions & 14 deletions src/DirectiveFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,13 @@
namespace Stillat\BladeDirectives;

use Illuminate\Support\Facades\Blade;
use ReflectionException;
use ReflectionFunction;
use ReflectionParameter;
use ReflectionException;
use Stillat\Primitives\Parser;

class DirectiveFactory
{

/**
* The Parser instance.
*
Expand All @@ -28,8 +27,8 @@ public function __construct(Parser $parser)
*
* Directive handlers will have access to the provided parameters through $this->parameters.
*
* @param string $name
* @param callable $handler
* @param string $name
* @param callable $handler
*/
public function params($name, callable $handler)
{
Expand All @@ -39,8 +38,8 @@ public function params($name, callable $handler)
/**
* Register a handler for a custom Blade directive.
*
* @param string $name
* @param callable $handler
* @param string $name
* @param callable $handler
*/
public function make($name, callable $handler)
{
Expand All @@ -50,8 +49,8 @@ public function make($name, callable $handler)
/**
* Register a handler for a custom compiled Blade directive.
*
* @param string $name
* @param callable $handler
* @param string $name
* @param callable $handler
*/
public function compile($name, $handler)
{
Expand Down Expand Up @@ -89,7 +88,7 @@ private function getFactoryClosure($handler, $compileResult)
$paramCompiler->setParameters($associatedParams);
$handler = $handler->bindTo($paramCompiler);

$result = call_user_func_array($handler, $associatedParams);
$result = call_user_func_array($handler, $associatedParams);

if ($compileResult) {
return $paramCompiler->compile($result);
Expand All @@ -102,10 +101,11 @@ private function getFactoryClosure($handler, $compileResult)
/**
* Associates the reflected parameters with their parsed values.
*
* @param ReflectionParameter[] $directiveParameters
* @param string[] $expressionParameters
* @param bool $returnOnlyExpressionArgs
* @param ReflectionParameter[] $directiveParameters
* @param string[] $expressionParameters
* @param bool $returnOnlyExpressionArgs
* @return array
*
* @throws ReflectionException
*/
private function associateParameters($directiveParameters, $expressionParameters, $returnOnlyExpressionArgs = false)
Expand Down Expand Up @@ -145,7 +145,7 @@ private function associateParameters($directiveParameters, $expressionParameters
}
}

if (!$didFind) {
if (! $didFind) {
$argsToUse[] = $this->getDefaultExpression($callbackArg);
}
}
Expand Down Expand Up @@ -195,4 +195,4 @@ private function getDefaultExpression(ReflectionParameter $parameter)

return $defaultExpression;
}
}
}
17 changes: 6 additions & 11 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
<?php

use Orchestra\Testbench\TestCase;
use Illuminate\Support\Facades\Blade;
use Stillat\BladeDirectives\Support\Facades\Directive;
use Orchestra\Testbench\TestCase;
use Stillat\BladeDirectives\DirectiveContainer;
use Stillat\BladeDirectives\Support\Facades\Directive;

class ParserTest extends TestCase
{

public function test_directives_receive_parameters()
{
Directive::make('test', function ($param1, $param2, $param3, $param4) {
return $param1.'---'.$param2.'---'.$param3.'---'.$param4;
});
Directive::make('test', function ($param1, $param2, $param3, $param4) {
return $param1.'---'.$param2.'---'.$param3.'---'.$param4;
});

$template = <<<'BLADE'
@test('hello', 'world', [1,2,3,'four', 'five' => [1, env('something', 'default')]], 'six')
Expand All @@ -30,7 +29,6 @@ public function test_param_directives_receives_expression_but_has_access_to_para

Directive::params('test', function ($expression) use (&$directiveExpression, &$directiveParams) {
/** @var $this DirectiveContainer */

$directiveExpression = $expression;
$directiveParams = $this->parameters;

Expand Down Expand Up @@ -63,12 +61,10 @@ public function test_directives_can_define_default_values()

$this->assertSame('$varName---((null) ?? (\'1234\'))', $result);


$result = Blade::compileString('@test($varName, $anotherVarName)');

$this->assertSame('$varName---(($anotherVarName) ?? (\'1234\'))', $result);


Directive::make('test', function ($name, $default = '1234', $another = 1234) {
return $name.'---'.$default.'---'.$another;
});
Expand All @@ -77,7 +73,6 @@ public function test_directives_can_define_default_values()

$this->assertSame('$varName---((null) ?? (\'1234\'))---((null) ?? (1234))', $result);


$result = Blade::compileString('@test($varName, "test")');

$this->assertSame('$varName---(("test") ?? (\'1234\'))---((null) ?? (1234))', $result);
Expand All @@ -89,7 +84,7 @@ public function test_directives_can_define_default_values()
public function test_parameters_can_be_compiled()
{
Directive::compile('test', function ($value = []) {
return '<?php foreach ($value as $testVar) {
return '<?php foreach ($value as $testVar) {
echo $testVar;
}';
});
Expand Down

0 comments on commit 7308fb4

Please sign in to comment.