Skip to content

Commit

Permalink
Merge pull request #1 from Stillat/analysis-EA6J6m
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
JohnathonKoster authored Sep 18, 2021
2 parents 57521ff + 146a7df commit dfef106
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 33 deletions.
14 changes: 6 additions & 8 deletions src/Evaluator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

class Evaluator
{

public function evaluate($node)
{
if ($node instanceof LNumber) {
Expand All @@ -20,11 +19,11 @@ public function evaluate($node)
return floatval($node->value);
} elseif ($node instanceof ConstFetch) {
return $this->getConstantValue($node->name->parts[0]);
} else if ($node instanceof Array_) {
} elseif ($node instanceof Array_) {
return $this->evaluateArray($node);
} else if ($node instanceof String_) {
} elseif ($node instanceof String_) {
return $node->value;
} else if ($node instanceof UnaryMinus) {
} elseif ($node instanceof UnaryMinus) {
return -1 * $this->evaluate($node->expr);
}

Expand All @@ -37,9 +36,9 @@ private function getConstantValue($value)

if ($checkValue == 'null') {
return null;
} else if ($checkValue == 'true') {
} elseif ($checkValue == 'true') {
return true;
} else if ($checkValue == 'false') {
} elseif ($checkValue == 'false') {
return false;
}

Expand All @@ -65,5 +64,4 @@ protected function evaluateArray(Array_ $array)

return $arrayValues;
}

}
}
14 changes: 6 additions & 8 deletions src/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class Parser
{

/**
* @var Php7
*/
Expand All @@ -33,8 +32,8 @@ public function __construct()

/**
* Parses the input string to produce an array of PHP runtime values.
*
* @param string $string The string.
*
* @param string $string The string.
* @return array
*/
public function parseString($string)
Expand All @@ -55,14 +54,14 @@ public function parseString($string)
/**
* Converts the input string into an array containing a method and values.
*
* @param string $string The input.
* @param string $string The input.
* @return array|null
*/
public function parseMethod($string)
{
$string = trim($string);

if (!StringUtilities::endsWith($string, ')')) {
if (! StringUtilities::endsWith($string, ')')) {
return $this->parseString($string);
}

Expand All @@ -73,11 +72,10 @@ public function parseMethod($string)
$args = $this->parseString(mb_substr($parts[1], 0, -1));

return [
$method, $args
$method, $args,
];
}

return null;
}

}
}
4 changes: 1 addition & 3 deletions src/Utilities/StringUtilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

class StringUtilities
{

/**
* Determine if a given string ends with a given substring.
*
Expand All @@ -26,5 +25,4 @@ public static function endsWith($haystack, $needles)

return false;
}

}
}
24 changes: 11 additions & 13 deletions tests/ParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@

class ParserTest extends TestCase
{

protected $parser;

protected $strings = [
'test',
'with spaces',
'with \'\\ \ escape'
'with \'\\ \ escape',
];

protected $numbers = [
-1,
0,
32.32,
0b11111111,
0123
0123,
];

public function setUp(): void
Expand All @@ -46,17 +45,17 @@ public function test_it_parses_simple_arrays()
{
$input = '[1, 2, 3, 4, "five"]';
$this->assertSame([
1, 2, 3, 4, "five"
1, 2, 3, 4, 'five',
], $this->parser->parseString($input)[0]);
}

public function test_it_parses_associative_arrays()
{
$input = '[1 => "one", 2 => "two", "three" => 3]';
$this->assertSame([
1 => "one",
2 => "two",
"three" => 3
1 => 'one',
2 => 'two',
'three' => 3,
], $this->parser->parseString($input)[0]);
}

Expand All @@ -70,8 +69,8 @@ public function test_it_parses_nested_arrays()
{
$input = '[[[[["one" => [1,2,3,4]]]]]]';

$this->assertSame([[[[["one" => [
1,2,3,4
$this->assertSame([[[[['one' => [
1, 2, 3, 4,
]]]]]], $this->parser->parseString($input)[0]);
}

Expand All @@ -95,9 +94,8 @@ public function test_extract_method()
'randomElement',
[
['foo', 'bar'],
3
]
3,
],
], $this->parser->parseMethod('randomElement(["foo", "bar"], 3)'));
}

}
}
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<?php

require_once __DIR__.'/../vendor/autoload.php';
require_once __DIR__.'/../vendor/autoload.php';

0 comments on commit dfef106

Please sign in to comment.