diff --git a/Utils/Parser/Php/ArrayParser.php b/Utils/Parser/Php/ArrayParser.php index 78b1d5bf5..b202a8219 100644 --- a/Utils/Parser/Php/ArrayParser.php +++ b/Utils/Parser/Php/ArrayParser.php @@ -30,7 +30,6 @@ namespace phpOMS\Utils\Parser\Php; */ class ArrayParser { - /** * Saving array to file. * diff --git a/Utils/Parser/Php/ClassParser.php b/Utils/Parser/Php/ClassParser.php index 7ca30b225..9072685f8 100644 --- a/Utils/Parser/Php/ClassParser.php +++ b/Utils/Parser/Php/ClassParser.php @@ -30,6 +30,8 @@ namespace phpOMS\Utils\Parser\Php; */ class ClassParser { + const INDENT = 4; + private $isFinal = false; private $isAbstract = false; diff --git a/Utils/Parser/Php/FunctionParser.php b/Utils/Parser/Php/FunctionParser.php index 06c51bd39..360c74401 100644 --- a/Utils/Parser/Php/FunctionParser.php +++ b/Utils/Parser/Php/FunctionParser.php @@ -30,8 +30,6 @@ namespace phpOMS\Utils\Parser\Php; */ class FunctionParser { - const INDENT = 4; - private $name = ''; private $visibility = Visibility::_PUBLIC; @@ -148,7 +146,7 @@ class FunctionParser public function parse() : string { $function = ''; - $member .= str_repeat(' ', self::INDENT); + $member .= str_repeat(' ', ClassParser::INDENT); if($this->isFinal) { $member .= 'final '; @@ -168,18 +166,29 @@ class FunctionParser $parameters = ''; foreach($this->parameters as $name => $para) { - $parameters = (isset($para['typehint']) ? $para['typehint'] . ' ': '') . $para['name'] . (array_key_exists('default', $para) ? ' = ' . MemberParser::parseVariable($para['default']) : '') . ', '; + $parameters = (isset($para['typehint']) ? $para['typehint'] . ' ' : '') . $para['name'] . (array_key_exists('default', $para) ? ' = ' . MemberParser::parseVariable($para['default']) : '') . ', '; } $member .= rtrim($parameters, ', ') . ') '; $member .= ($this->return ?? '') . PHP_EOL; if(isset($this->body)) { - $member .= '{' . PHP_EOL . $this->body . PHP_EOL . '}'; + $member .= str_repeat(' ', ClassParser::INDENT) . '{' . PHP_EOL . $this->addIndent($this->body) . PHP_EOL . str_repeat(' ', ClassParser::INDENT) . '}'; } else { $member .= ';'; } return $member; } + + private function addIndent($body) : string + { + $body = preg_split('/\r\n|\r|\n/', $this->body); + + foreach($body as &$line) { + $line = str_repeat(' ', ClassParser::INDENT) . $line; + } + + return $body; + } } \ No newline at end of file diff --git a/Utils/Parser/Php/MemberParser.php b/Utils/Parser/Php/MemberParser.php index f7580a8be..7db17d715 100644 --- a/Utils/Parser/Php/MemberParser.php +++ b/Utils/Parser/Php/MemberParser.php @@ -30,8 +30,6 @@ namespace phpOMS\Utils\Parser\Php; */ class MemberParser { - const INDENT = 4; - private $name = ''; private $visibility = Visibility::_PUBLIC; @@ -90,7 +88,7 @@ class MemberParser public function parse() : string { $member = ''; - $member .= str_repeat(' ', self::INDENT); + $member .= str_repeat(' ', ClassParser::INDENT); $member .= $this->visibility . ' ';