Skip to content

Commit

Permalink
TASK: Update coding style to core standards
Browse files Browse the repository at this point in the history
- add codes to exception
- use strict_types
- add return types
  • Loading branch information
mficzel committed May 14, 2019
1 parent 2d87876 commit f9bc230
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 71 deletions.
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Neos\Fusion\Afx\Parser;

/*
Expand All @@ -12,8 +14,9 @@
*/

/**
* AFX-Exception
* Class AfxParserException
* @package Neos\Fusion\Afx\Parser
*/
class Exception extends \Exception
class AfxParserException extends \Exception
{
}
19 changes: 15 additions & 4 deletions Classes/Parser/Expression/Expression.php
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Neos\Fusion\Afx\Parser\Expression;

/*
Expand All @@ -11,25 +13,34 @@
* source code.
*/

use Neos\Fusion\Afx\Parser\Exception;
use Neos\Fusion\Afx\Parser\AfxParserException;
use Neos\Fusion\Afx\Parser\Lexer;

/**
* Class Expression
* @package Neos\Fusion\Afx\Parser\Expression
*/
class Expression
{
public static function parse(Lexer $lexer)
/**
* @param Lexer $lexer
* @return string
* @throws AfxParserException
*/
public static function parse(Lexer $lexer): string
{
$contents = '';
$braceCount = 0;

if ($lexer->isOpeningBrace()) {
$lexer->consume();
} else {
throw new Exception('Expression without braces');
throw new AfxParserException('Expression without braces', 1557860467921);
}

while (true) {
if ($lexer->isEnd()) {
throw new Exception(sprintf('Unfinished Expression "%s"', $contents));
throw new AfxParserException(sprintf('Unfinished Expression "%s"', $contents), 1557860496139);
}

if ($lexer->isOpeningBrace()) {
Expand Down
19 changes: 15 additions & 4 deletions Classes/Parser/Expression/Identifier.php
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Neos\Fusion\Afx\Parser\Expression;

/*
Expand All @@ -11,12 +13,21 @@
* source code.
*/

use Neos\Fusion\Afx\Parser\Exception;
use Neos\Fusion\Afx\Parser\AfxParserException;
use Neos\Fusion\Afx\Parser\Lexer;

/**
* Class Identifier
* @package Neos\Fusion\Afx\Parser\Expression
*/
class Identifier
{
public static function parse(Lexer $lexer)
/**
* @param Lexer $lexer
* @return string
* @throws AfxParserException
*/
public static function parse(Lexer $lexer): string
{
$identifier = '';

Expand All @@ -38,11 +49,11 @@ public static function parse(Lexer $lexer)
break;
default:
$unexpected_character = $lexer->consume();
throw new Exception(sprintf(
throw new AfxParserException(sprintf(
'Unexpected character "%s" in identifier "%s"',
$unexpected_character,
$identifier
));
), 1557860650835);
}
}
}
Expand Down
39 changes: 25 additions & 14 deletions Classes/Parser/Expression/Node.php
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Neos\Fusion\Afx\Parser\Expression;

/*
Expand All @@ -11,12 +13,21 @@
* source code.
*/

use Neos\Fusion\Afx\Parser\Exception;
use Neos\Fusion\Afx\Parser\AfxParserException;
use Neos\Fusion\Afx\Parser\Lexer;

/**
* Class Node
* @package Neos\Fusion\Afx\Parser\Expression
*/
class Node
{
public static function parse(Lexer $lexer)
/**
* @param Lexer $lexer
* @return array
* @throws AfxParserException
*/
public static function parse(Lexer $lexer): array
{
if ($lexer->isOpeningBracket()) {
$lexer->consume();
Expand Down Expand Up @@ -63,14 +74,14 @@ public static function parse(Lexer $lexer)
'selfClosing' => true
];
} else {
throw new Exception(sprintf('Self closing tag "%s" misses closing bracket.', $identifier));
throw new AfxParserException(sprintf('Self closing tag "%s" misses closing bracket.', $identifier), 1557860567682);
}
}

if ($lexer->isClosingBracket()) {
$lexer->consume();
} else {
throw new Exception(sprintf('Tag "%s" did not end with closing bracket.', $identifier));
throw new AfxParserException(sprintf('Tag "%s" did not end with closing bracket.', $identifier), 1557860573945);
}

$children = NodeList::parse($lexer);
Expand All @@ -81,26 +92,26 @@ public static function parse(Lexer $lexer)
if ($lexer->isForwardSlash()) {
$lexer->consume();
} else {
throw new Exception(sprintf(
throw new AfxParserException(sprintf(
'Opening-bracket for closing of tag "%s" was not followed by slash.',
$identifier
));
), 1557860584196);
}
} else {
throw new Exception(sprintf(
throw new AfxParserException(sprintf(
'Opening-bracket for closing of tag "%s" expected.',
$identifier
));
), 1557860587680);
}

$closingIdentifier = Identifier::parse($lexer);

if ($closingIdentifier !== $identifier) {
throw new Exception(sprintf(
throw new AfxParserException(sprintf(
'Closing-tag identifier "%s" did not match opening-tag identifier "%s".',
$closingIdentifier,
$identifier
));
), 1557860595281);
}

if ($lexer->isClosingBracket()) {
Expand All @@ -112,14 +123,14 @@ public static function parse(Lexer $lexer)
'selfClosing' => false
];
} else {
throw new Exception(sprintf('Closing tag "%s" did not end with closing-bracket.', $identifier));
throw new AfxParserException(sprintf('Closing tag "%s" did not end with closing-bracket.', $identifier), 1557860618559);
}

if ($lexer->isEnd()) {
throw new Exception(sprintf('Tag was %s is not closed.', $identifier));
throw new AfxParserException(sprintf('Tag was %s is not closed.', $identifier), 1557860622684);
}
} catch (Exception $e) {
throw new Exception(sprintf('<%s> %s', $identifier, $e->getMessage()));
} catch (AfxParserException $e) {
throw new AfxParserException(sprintf('<%s> %s', $identifier, $e->getMessage()), 1557860627201);
}
}
}
15 changes: 13 additions & 2 deletions Classes/Parser/Expression/NodeList.php
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Neos\Fusion\Afx\Parser\Expression;

/*
Expand All @@ -11,12 +13,21 @@
* source code.
*/

use Neos\Fusion\Afx\Parser\Exception;
use Neos\Fusion\Afx\Parser\AfxParserException;
use Neos\Fusion\Afx\Parser\Lexer;

/**
* Class NodeList
* @package Neos\Fusion\Afx\Parser\Expression
*/
class NodeList
{
public static function parse(Lexer $lexer)
/**
* @param Lexer $lexer
* @return array
* @throws AfxParserException
*/
public static function parse(Lexer $lexer): array
{
$contents = [];
$currentText = '';
Expand Down
21 changes: 16 additions & 5 deletions Classes/Parser/Expression/Prop.php
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Neos\Fusion\Afx\Parser\Expression;

/*
Expand All @@ -11,12 +13,21 @@
* source code.
*/

use Neos\Fusion\Afx\Parser\Exception;
use Neos\Fusion\Afx\Parser\AfxParserException;
use Neos\Fusion\Afx\Parser\Lexer;

/**
* Class Prop
* @package Neos\Fusion\Afx\Parser\Expression
*/
class Prop
{
public static function parse(Lexer $lexer)
/**
* @param Lexer $lexer
* @return array
* @throws AfxParserException
*/
public static function parse(Lexer $lexer): array
{
$identifier = Identifier::parse($lexer);

Expand All @@ -40,10 +51,10 @@ public static function parse(Lexer $lexer)
];
break;
default:
throw new Exception(sprintf(
throw new AfxParserException(sprintf(
'Prop-assignment "%s" was not followed by quotes or braces',
$identifier
));
), 1557860545099);
}
} elseif ($lexer->isWhiteSpace() || $lexer->isForwardSlash() || $lexer->isClosingBracket()) {
$value = [
Expand All @@ -52,7 +63,7 @@ public static function parse(Lexer $lexer)
'identifier' => $identifier
];
} else {
throw new Exception(sprintf('Prop identifier "%s" is neither assignment nor boolean', $identifier));
throw new AfxParserException(sprintf('Prop identifier "%s" is neither assignment nor boolean', $identifier), 1557860552278);
}

return $value;
Expand Down
19 changes: 15 additions & 4 deletions Classes/Parser/Expression/Spread.php
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Neos\Fusion\Afx\Parser\Expression;

/*
Expand All @@ -11,12 +13,21 @@
* source code.
*/

use Neos\Fusion\Afx\Parser\Exception;
use Neos\Fusion\Afx\Parser\AfxParserException;
use Neos\Fusion\Afx\Parser\Lexer;

/**
* Class Spread
* @package Neos\Fusion\Afx\Parser\Expression
*/
class Spread
{
public static function parse(Lexer $lexer)
/**
* @param Lexer $lexer
* @return array
* @throws AfxParserException
*/
public static function parse(Lexer $lexer): array
{
$contents = '';
$braceCount = 0;
Expand All @@ -27,12 +38,12 @@ public static function parse(Lexer $lexer)
$lexer->consume();
$lexer->consume();
} else {
throw new Exception('Spread without braces');
throw new AfxParserException('Spread without braces', 1557860522837);
}

while (true) {
if ($lexer->isEnd()) {
throw new Exception(sprintf('Unfinished Spread "%s"', $contents));
throw new AfxParserException(sprintf('Unfinished Spread "%s"', $contents), 1557860526973);
}

if ($lexer->isOpeningBrace()) {
Expand Down
15 changes: 11 additions & 4 deletions Classes/Parser/Expression/StringLiteral.php
@@ -1,4 +1,6 @@
<?php
declare(strict_types=1);

namespace Neos\Fusion\Afx\Parser\Expression;

/*
Expand All @@ -11,7 +13,7 @@
* source code.
*/

use Neos\Fusion\Afx\Parser\Exception;
use Neos\Fusion\Afx\Parser\AfxParserException;
use Neos\Fusion\Afx\Parser\Lexer;

/**
Expand All @@ -20,20 +22,25 @@
*/
class StringLiteral
{
public static function parse(Lexer $lexer)
/**
* @param Lexer $lexer
* @return string
* @throws AfxParserException
*/
public static function parse(Lexer $lexer): string
{
$openingQuoteSign = '';
$contents = '';
$willBeEscaped = false;
if ($lexer->isSingleQuote() || $lexer->isDoubleQuote()) {
$openingQuoteSign = $lexer->consume();
} else {
throw new Exception('Unquoted String literal');
throw new AfxParserException('Unquoted String literal', 1557860514707);
}

while (true) {
if ($lexer->isEnd()) {
throw new Exception(sprintf('Unfinished string literal "%s"', $contents));
throw new AfxParserException(sprintf('Unfinished string literal "%s"', $contents), 1557860504068);
}

if ($lexer->isBackSlash() && !$willBeEscaped) {
Expand Down

0 comments on commit f9bc230

Please sign in to comment.