-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from Riimu/next
Added support for class resolution operator strings
- Loading branch information
Showing
23 changed files
with
315 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,33 @@ | ||
language: php | ||
sudo: false | ||
dist: trusty | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- hhvm | ||
- 7.2 | ||
|
||
cache: | ||
directories: | ||
- vendor | ||
- build/.composer-cache | ||
|
||
before_install: | ||
- export COMPOSER_CACHE_DIR="$(pwd)/build/.composer-cache" | ||
- export XDEBUG="/home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini" | ||
- is_hhvm () { [[ $TRAVIS_PHP_VERSION =~ ^hhvm ]]; } | ||
- is_hhvm || mv -v "$XDEBUG" "$XDEBUG.disabled" | ||
- mv -v "$XDEBUG" "$XDEBUG.disabled" | ||
|
||
install: | ||
- travis_retry composer update -a --no-interaction | ||
- travis_retry wget https://scrutinizer-ci.com/ocular.phar | ||
- mkdir -p build/php_codesniffer build/php-cs-fixer build/ocular | ||
- composer require --no-suggest --no-progress -n -a -d build/php-cs-fixer "friendsofphp/php-cs-fixer:^2.12" | ||
- composer require --no-suggest --no-progress -n -a -d build/php_codesniffer "squizlabs/php_codesniffer:^3.3" | ||
- composer require --no-suggest --no-progress -n -a -d build/ocular "scrutinizer/ocular:^1.5" | ||
- composer update --no-suggest --no-progress -n -a | ||
|
||
script: | ||
- vendor/bin/phpcs --standard=PSR2 src tests | ||
- vendor/bin/php-cs-fixer fix -v --dry-run --allow-risky=yes --using-cache=no | ||
- if is_hhvm; then echo "xdebug.enable = On" >> /etc/hhvm/php.ini; else mv -v "$XDEBUG.disabled" "$XDEBUG"; fi | ||
- vendor/bin/phpunit --coverage-clover=coverage.clover --coverage-text | ||
- build/php_codesniffer/vendor/bin/phpcs -p --standard=PSR2 src tests | ||
- build/php-cs-fixer/vendor/bin/php-cs-fixer fix -v --dry-run --allow-risky=yes --using-cache=no | ||
- mv -v "$XDEBUG.disabled" "$XDEBUG" | ||
- vendor/bin/phpunit --coverage-clover=build/coverage.clover --coverage-text | ||
|
||
after_script: | ||
- is_hhvm || php ocular.phar code-coverage:upload --format=php-clover coverage.clover | ||
- build/ocular/vendor/bin/ocular code-coverage:upload --format=php-clover build/coverage.clover |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
/* Shows an example of how you can take advantage of class resolution in the | ||
generated code. */ | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$encoder = new \Riimu\Kit\PHPEncoder\PHPEncoder([ | ||
'string.classes' => [ | ||
'Riimu\\', | ||
'PHPUnit\\Framework\\TestCase', | ||
'DateTime', | ||
], | ||
'string.imports' => [ | ||
'Riimu\\Kit\\PHPEncoder\\' => '', | ||
'PHPUnit\\Framework\\TestCase' => 'TestCase', | ||
], | ||
]); | ||
|
||
|
||
echo "<?php | ||
namespace Riimu\Kit\PHPEncoder; | ||
use PHPUnit\Framework\TestCase; | ||
var_dump("; | ||
|
||
echo $encoder->encode([ | ||
\PHPUnit\Framework\TestCase::class, | ||
\Riimu\Kit\PHPEncoder\PHPEncoder::class, | ||
\Riimu\Kit\PHPEncoder\Encoder\Encoder::class, | ||
\DateTime::class, | ||
\DateTimeInterface::class, // Will be encoded as plain string, since it's not allowed by string.classes | ||
]); | ||
|
||
echo ");\n"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,20 +5,20 @@ | |
/** | ||
* Encoder for array values. | ||
* @author Riikka Kalliomäki <[email protected]> | ||
* @copyright Copyright (c) 2014-2017 Riikka Kalliomäki | ||
* @copyright Copyright (c) 2014-2018 Riikka Kalliomäki | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
class ArrayEncoder implements Encoder | ||
{ | ||
/** @var array Default values for options in the encoder */ | ||
private static $defaultOptions = [ | ||
'array.short' => true, | ||
'array.base' => 0, | ||
'array.short' => true, | ||
'array.base' => 0, | ||
'array.indent' => 4, | ||
'array.align' => false, | ||
'array.align' => false, | ||
'array.inline' => 70, | ||
'array.omit' => true, | ||
'array.eol' => false, | ||
'array.omit' => true, | ||
'array.eol' => false, | ||
]; | ||
|
||
public function getDefaultOptions() | ||
|
@@ -28,7 +28,7 @@ public function getDefaultOptions() | |
|
||
public function supports($value) | ||
{ | ||
return is_array($value); | ||
return \is_array($value); | ||
} | ||
|
||
public function encode($value, $depth, array $options, callable $encode) | ||
|
@@ -107,7 +107,7 @@ private function getInlineArray(array $lines, array $options) | |
|
||
if (preg_match('/[\r\n\t]/', $output)) { | ||
return false; | ||
} elseif ($options['array.inline'] === true || strlen($output) <= (int) $options['array.inline']) { | ||
} elseif ($options['array.inline'] === true || \strlen($output) <= (int) $options['array.inline']) { | ||
return $output; | ||
} | ||
|
||
|
@@ -125,7 +125,7 @@ private function buildArray(array $lines, $depth, array $options) | |
{ | ||
$indent = $this->buildIndent($options['array.base'], $options['array.indent'], $depth + 1); | ||
$last = $this->buildIndent($options['array.base'], $options['array.indent'], $depth); | ||
$eol = $options['array.eol'] === false ? PHP_EOL : (string) $options['array.eol']; | ||
$eol = $options['array.eol'] === false ? \PHP_EOL : (string) $options['array.eol']; | ||
|
||
return $this->wrap( | ||
sprintf('%s%s%s,%1$s%s', $eol, $indent, implode(',' . $eol . $indent, $lines), $last), | ||
|
@@ -153,10 +153,10 @@ private function wrap($string, $short) | |
*/ | ||
private function buildIndent($base, $indent, $depth) | ||
{ | ||
$base = is_int($base) ? str_repeat(' ', $base) : (string) $base; | ||
$base = \is_int($base) ? str_repeat(' ', $base) : (string) $base; | ||
|
||
return $depth === 0 ? $base : $base . str_repeat( | ||
is_int($indent) ? str_repeat(' ', $indent) : (string) $indent, | ||
\is_int($indent) ? str_repeat(' ', $indent) : (string) $indent, | ||
$depth | ||
); | ||
} | ||
|
@@ -180,7 +180,7 @@ private function getAlignedPairs(array $array, callable $encode) | |
$format = sprintf('%%-%ds => %%s', max(array_map('strlen', $keys))); | ||
$pairs = []; | ||
|
||
for ($i = 0, $count = count($keys); $i < $count; $i++) { | ||
for ($i = 0, $count = \count($keys); $i < $count; $i++) { | ||
$pairs[] = sprintf($format, $keys[$i], $values[$i]); | ||
} | ||
|
||
|
@@ -225,7 +225,7 @@ private function canOmitKey($key, & $nextIndex) | |
{ | ||
$result = $key === $nextIndex; | ||
|
||
if (is_int($key)) { | ||
if (\is_int($key)) { | ||
$nextIndex = max($key + 1, $nextIndex); | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
/** | ||
* Encoder for boolean values. | ||
* @author Riikka Kalliomäki <[email protected]> | ||
* @copyright Copyright (c) 2014-2017 Riikka Kalliomäki | ||
* @copyright Copyright (c) 2014-2018 Riikka Kalliomäki | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
class BooleanEncoder implements Encoder | ||
|
@@ -22,7 +22,7 @@ public function getDefaultOptions() | |
|
||
public function supports($value) | ||
{ | ||
return is_bool($value); | ||
return \is_bool($value); | ||
} | ||
|
||
public function encode($value, $depth, array $options, callable $encode) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
/** | ||
* Interface for different types of value encoders. | ||
* @author Riikka Kalliomäki <[email protected]> | ||
* @copyright Copyright (c) 2014-2017 Riikka Kalliomäki | ||
* @copyright Copyright (c) 2014-2018 Riikka Kalliomäki | ||
* @license http://opensource.org/licenses/mit-license.php MIT License | ||
*/ | ||
interface Encoder | ||
|
Oops, something went wrong.