Skip to content
This repository has been archived by the owner on Mar 19, 2020. It is now read-only.

Commit

Permalink
@ConfigArray now supports omitting the type (mixed)
Browse files Browse the repository at this point in the history
  • Loading branch information
TonyBogdanov committed Mar 24, 2018
1 parent e79597c commit 6fbb714
Show file tree
Hide file tree
Showing 31 changed files with 1,381 additions and 1,338 deletions.
2 changes: 1 addition & 1 deletion classes/Annotation/ConfigArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class ConfigArray extends Config
{
/**
* @var null|\ClassConfig\Annotation\ConfigEntryTypeHintInterface
* @var \ClassConfig\Annotation\ConfigEntryTypeHintInterface
*/
public $value;
}
29 changes: 20 additions & 9 deletions classes/ClassGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ protected static function camelCase(string $value): string
*/
protected function getTypeHint(string $type)
{
return '[]' === substr($type, -2) ? 'array' : $type;
if ('[]' === substr($type, -2)) {
return 'array';
}

if ('mixed' === $type) {
return '';
}

return $type;
}

/**
Expand Down Expand Up @@ -150,7 +158,10 @@ public function generateGet(string $name, string $type): ClassGenerator
)->setReturnType($this->getTypeHint($type))
->setReturnNullable(true)
->setBody(
'return isset($this->__' . $name . '__[0]) ? $this->__' . $name . '__[0] : $this->__' . $name . '__[1];'
'if (isset($this->__' . $name . '__[0])) {' . PHP_EOL .
' return $this->__' . $name . '__[0];' . PHP_EOL .
'}' . PHP_EOL .
'return $this->__' . $name . '__[1];'
);
return $this;
}
Expand Down Expand Up @@ -221,11 +232,14 @@ public function generateArrayGet(string $name, string $type): ClassGenerator
$this->class
->addMethod(static::camelCase('get_' . $name))
->addComment(
'@return ' . $this->getCommentTypeHint($type)
'@return null|' . $this->getCommentTypeHint($type)
)->setReturnType($this->getTypeHint($type))
->setReturnNullable(true)
->setBody(
'return isset($this->__' . $name . '__[0]) ? $this->__' . $name . '__[0] : null;'
'if (isset($this->__' . $name . '__[0])) {' . PHP_EOL .
' return $this->__' . $name . '__[0];' . PHP_EOL .
'}' . PHP_EOL .
'return null;'
);
return $this;
}
Expand Down Expand Up @@ -293,11 +307,8 @@ public function generateArraySetAt(string $name, string $type): ClassGenerator
'@return ' . $this->class->getName()
)->setReturnType($this->getCanonicalClassName())
->setBody(
'if (' . PHP_EOL .
' 0 > $index ||' . PHP_EOL .
' (0 < $index && (!isset($this->__' . $name . '__[0]) || empty($this->__' . $name .
'__[0])) || $index > count($this->__' . $name . '__[0]))' . PHP_EOL .
') {' . PHP_EOL .
'if (0 > $index || (0 < $index && (!isset($this->__' . $name . '__[0]) ||' . PHP_EOL .
' empty($this->__' . $name . '__[0])) || $index > count($this->__' . $name . '__[0]))) {' . PHP_EOL .
' return $this;' . PHP_EOL .
'}' . PHP_EOL . PHP_EOL .
'if (!isset($this->__' . $name . '__[0])) {' . PHP_EOL .
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage/AbstractConfig.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ <h4>Legend</h4>
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 12:19:14 EET 2018.</small>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 14:38:47 EET 2018.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage/Annotation/Config.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h4>Legend</h4>
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 12:19:14 EET 2018.</small>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 14:38:47 EET 2018.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage/Annotation/ConfigArray.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ <h4>Legend</h4>
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 12:19:14 EET 2018.</small>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 14:38:47 EET 2018.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage/Annotation/ConfigBoolean.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h4>Legend</h4>
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 12:19:14 EET 2018.</small>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 14:38:47 EET 2018.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage/Annotation/ConfigEntryInterface.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ <h4>Legend</h4>
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 12:19:14 EET 2018.</small>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 14:38:47 EET 2018.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ <h4>Legend</h4>
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 12:19:14 EET 2018.</small>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 14:38:47 EET 2018.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage/Annotation/ConfigFloat.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h4>Legend</h4>
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 12:19:14 EET 2018.</small>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 14:38:47 EET 2018.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage/Annotation/ConfigInteger.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h4>Legend</h4>
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 12:19:14 EET 2018.</small>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 14:38:47 EET 2018.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage/Annotation/ConfigObject.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h4>Legend</h4>
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 12:19:14 EET 2018.</small>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 14:38:47 EET 2018.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage/Annotation/ConfigString.php.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ <h4>Legend</h4>
<span class="warning"><strong>Dead Code</strong></span>
</p>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 12:19:14 EET 2018.</small>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 14:38:47 EET 2018.</small>
</p>
<a title="Back to the top" id="toplink" href="#"><span class="glyphicon glyphicon-arrow-up"></span></a>
</footer>
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage/Annotation/dashboard.html
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ <h3>Project Risks</h3>
<footer>
<hr/>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 12:19:14 EET 2018.</small>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 14:38:47 EET 2018.</small>
</p>
</footer>
</div>
Expand Down
2 changes: 1 addition & 1 deletion docs/coverage/Annotation/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ <h4>Legend</h4>
<span class="success"><strong>High</strong>: 90% to 100%</span>
</p>
<p>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 12:19:14 EET 2018.</small>
<small>Generated by <a href="https://github.com/sebastianbergmann/php-code-coverage" target="_top">php-code-coverage 5.3.0-1-g982ce79</a> using <a href="https://secure.php.net/" target="_top">PHP 7.2.2</a> with <a href="https://xdebug.org/">Xdebug 2.6.0</a> and <a href="https://phpunit.de/">PHPUnit 6.5.5</a> at Sat Mar 24 14:38:47 EET 2018.</small>
</p>
</footer>
</div>
Expand Down
Loading

0 comments on commit 6fbb714

Please sign in to comment.