From 92230aeda0d1c018f09dd4340c2bd11ffbee9869 Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Thu, 20 Sep 2018 21:52:52 +0700 Subject: [PATCH 1/7] fix(initcmd): add missing path arg in projectExists() --- src/Console/InitCommand.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/InitCommand.php b/src/Console/InitCommand.php index 411c445..a985dd8 100644 --- a/src/Console/InitCommand.php +++ b/src/Console/InitCommand.php @@ -136,7 +136,7 @@ protected function prepareProjectPath(): string } if (\is_dir($path)) { - $this->projectExists($io); + $this->projectExists($io, $path); } else { \mkdir($path, 0777, true); } @@ -144,7 +144,7 @@ protected function prepareProjectPath(): string return $path; } - protected function projectExists(Interactor $io) + protected function projectExists(Interactor $io, string $path) { if (!$this->force && !$this->sync) { throw new InvalidArgumentException( From 72bc7fa1df69b0c065ff13de7c7ee616aac73caf Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Thu, 20 Sep 2018 21:53:27 +0700 Subject: [PATCH 2/7] fix(twig.generator): fix call() fn --- src/Generator/TwigGenerator.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Generator/TwigGenerator.php b/src/Generator/TwigGenerator.php index 3b048a9..73f2642 100644 --- a/src/Generator/TwigGenerator.php +++ b/src/Generator/TwigGenerator.php @@ -161,8 +161,8 @@ protected function initTwig() return \gmdate($f ?? 'Y-m-d H:i:s'); })); - $this->twig->addFilter(new \Twig_SimpleFilter('call', function ($fn) { - return $fn(\array_slice(\func_get_args(), 1)); + $this->twig->addFunction(new \Twig_Function('call', function ($fn) { + return $fn(...\array_slice(\func_get_args(), 1)); })); } From a8898a6626b4b4ad13934dde69a8a62c8976ab99 Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Thu, 20 Sep 2018 21:54:36 +0700 Subject: [PATCH 3/7] refactor(util.metadata): add throws, improve return/params --- src/Util/Metadata.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Util/Metadata.php b/src/Util/Metadata.php index a6c6dc6..f43803e 100644 --- a/src/Util/Metadata.php +++ b/src/Util/Metadata.php @@ -64,6 +64,7 @@ public function forReflectionMethod(\ReflectionMethod $method): array $parser = new DocBlock($method); $texts = $parser->texts(); $title = \array_shift($texts); + $throws = $parser->first('throws'); $metadata = [ 'name' => $method->name, @@ -73,25 +74,26 @@ public function forReflectionMethod(\ReflectionMethod $method): array 'isPublic' => $method->isPublic(), 'isAbstract' => $method->isAbstract(), 'maybeMagic' => \substr($method->name, 0, 2) === '__', + 'throws' => $throws ? \explode(' ', \trim($throws->getValue()), 2) : [], 'title' => $title, 'texts' => $texts, ]; $params = []; foreach ($parser->find('param') as $param) { - if (\preg_match('/(.*)\$(\w+)/', $param->getValue(), $match)) { - $params[$match[2]] = \trim($match[1]); + if (\preg_match('/(.*)\$(\w+)(.*)/', $param->getValue(), $match)) { + $params[$match[2]] = [\trim($match[1]), \trim($match[3])]; } } if (null !== $return = $parser->first('return')) { - $return = \preg_replace('/(\S+)(.*)/', '$1', $return->getValue()); + $return = \explode(' ', \trim($return->getValue()), 2); } - return $metadata + $this->getMethodParameters($method, $params, $return ?? ''); + return $metadata + $this->getMethodParameters($method, $params, $return ?? []); } - protected function getMethodParameters(\ReflectionMethod $method, array $docParams, string $return) + protected function getMethodParameters(\ReflectionMethod $method, array $docParams, array $return) { $params = []; $parser = new DocBlock($method); @@ -99,7 +101,7 @@ protected function getMethodParameters(\ReflectionMethod $method, array $docPara foreach ($method->getParameters() as $param) { $name = $param->name; if (!$param->hasType()) { - $params[] = \trim(($docParams[$name] ?? '') . " \$$name"); + $params[] = [\trim(($docParams[$name][0] ?? '') . " \$$name"), $docParams[$name][1] ?? '']; continue; } @@ -108,7 +110,7 @@ protected function getMethodParameters(\ReflectionMethod $method, array $docPara } if ($returnType = $method->getReturnType()) { - $return = $this->getRealType($returnType); + $return[0] = $this->getRealType($returnType); } return \compact('params', 'return'); From ef48c80043b5d9727ee638a5a098e10d56bd7876 Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Thu, 20 Sep 2018 21:56:48 +0700 Subject: [PATCH 4/7] chore(docs.tmpl): make collaspible. add throws. fix return/param --- resources/docs/docs.twig | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/resources/docs/docs.twig b/resources/docs/docs.twig index a9344a0..661c9f0 100644 --- a/resources/docs/docs.twig +++ b/resources/docs/docs.twig @@ -21,13 +21,24 @@ use {{class.classFqcn}}; > {{method.title}} {% endif %} +
Details … +
+ ```php -{{method.isStatic ? '::' : ''}}{{name}}({{method.params|join(', ')}}){{method.return ? ': ' ~ method.return : ''}} +{% set params = call('array_column', method.params, 0) %} +{{method.isStatic ? '::' : ''}}{{name}}({{params|join(', ')}}){{method.return ? ': ' ~ method.return[0] : ''}} ``` {% if method.texts %} -{{method.texts|join("\n")|replace({'':"```php",'':"```"})|raw}} +{{method.texts|join("\n\n")|replace({'':"```php", '':"```"})|raw|nl2br}} +{% endif %} +{% if method.throws %} + +> _Throws_ **{{method.throws[0]}}** {{ method.throws[1] ? '_' ~ method.throws[1] ~ '_' : '' }} {% endif %} + +
+
{% endfor %} **[⬆ back to top](#the-top)** From bb2798921de23d2caf20cb60fb52189a7401e84e Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Thu, 20 Sep 2018 22:04:56 +0700 Subject: [PATCH 5/7] test: fix git test --- tests/Util/GitTest.php | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/Util/GitTest.php b/tests/Util/GitTest.php index 3458d2b..b2e1ce2 100644 --- a/tests/Util/GitTest.php +++ b/tests/Util/GitTest.php @@ -18,17 +18,11 @@ class GitTest extends TestCase { public function testGetConfig() { - $git = new Git; + $git = new Git; + $conf = $git->getConfig(); - $this->assertArraySubset([ - 'core.repositoryformatversion' => '0', - 'core.filemode' => 'true', - 'core.bare' => 'false', - 'core.logallrefupdates' => 'true', - 'remote.origin.url' => 'https://github.com/adhocore/phint.git', - 'remote.origin.fetch' => '+refs/heads/master:refs/remotes/origin/master', - '' => '', - ], $git->getConfig()); + $this->assertArrayHasKey('remote.origin.url', $conf); + $this->assertContains('adhocore/phint.git', $conf['remote.origin.url']); } public function testGetConfigOnSpecificKey() From 3f3fc5ef823659bef0a628933a04726124dc15f7 Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Thu, 20 Sep 2018 22:05:13 +0700 Subject: [PATCH 6/7] test: fix meta test --- tests/Util/MetadataTest.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/Util/MetadataTest.php b/tests/Util/MetadataTest.php index 3da8730..9019c29 100644 --- a/tests/Util/MetadataTest.php +++ b/tests/Util/MetadataTest.php @@ -50,12 +50,13 @@ public function testForMethod() 'isPublic' => true, 'isAbstract' => false, 'maybeMagic' => false, + 'throws' => [], 'title' => null, 'texts' => [], 'params' => [ - 'string $classFqcn', + ['string $classFqcn', ''], ], - 'return' => 'array', + 'return' => ['array', ''], ], $result); } } From 0485057be07c0516ac9d17e018e83676d28ab84d Mon Sep 17 00:00:00 2001 From: Jitendra Adhikari Date: Thu, 20 Sep 2018 22:18:58 +0700 Subject: [PATCH 7/7] fix(util.meta): param must be array --- src/Util/Metadata.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Util/Metadata.php b/src/Util/Metadata.php index f43803e..23f20d0 100644 --- a/src/Util/Metadata.php +++ b/src/Util/Metadata.php @@ -106,11 +106,11 @@ protected function getMethodParameters(\ReflectionMethod $method, array $docPara continue; } - $params[] = $this->getRealType($param) . " \$$name"; + $params[] = [$this->getRealType($param) . " \$$name", $docParams[$name][1] ?? '']; } if ($returnType = $method->getReturnType()) { - $return[0] = $this->getRealType($returnType); + $return = [$this->getRealType($returnType), $return[1] ?? '']; } return \compact('params', 'return');