From f416ef449d3d2751ba2fbd2be5d96dbbe218b78a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Fri, 4 Dec 2015 20:52:36 +0200 Subject: [PATCH 1/8] Optimize argument loading --- .travis.yml | 8 +++++--- src/Path.php | 10 +++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/.travis.yml b/.travis.yml index d060888..ee6a7b5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ php: - 5.6 - 5.5 - 5.4 + - 7.0 + - hhvm cache: directories: @@ -14,8 +16,8 @@ before_install: - composer self-update install: - - composer require --no-update --no-interaction "phpunit/phpunit:4.*" "squizlabs/php_codesniffer:2.*" "fabpot/php-cs-fixer:1.*" - - travis_retry composer install --no-interaction + - composer require --no-update --no-interaction "phpunit/phpunit:*" "squizlabs/php_codesniffer:*" "fabpot/php-cs-fixer:*" + - travis_retry composer update --no-interaction --prefer-source - travis_retry wget https://scrutinizer-ci.com/ocular.phar script: @@ -24,4 +26,4 @@ script: - vendor/bin/php-cs-fixer fix --dry-run --diff after_script: - - php ocular.phar code-coverage:upload --format=php-clover coverage.clover + - if [ -f coverage.clover ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi diff --git a/src/Path.php b/src/Path.php index a4951c3..c6ab57c 100644 --- a/src/Path.php +++ b/src/Path.php @@ -61,10 +61,14 @@ public static function normalize($path, $prependDrive = true) */ public static function join($paths) { - $paths = array_map('strval', is_array($paths) ? $paths : func_get_args()); - $parts = self::getParts($paths); + $joins = []; - $absolute = self::isAbsolute($paths[0]); + foreach (is_array($paths) ? $paths : func_get_args() as $path) { + $joins[] = (string) $path; + } + + $parts = self::getParts($joins); + $absolute = self::isAbsolute($joins[0]); $root = $absolute ? array_shift($parts) . DIRECTORY_SEPARATOR : ''; $parts = self::resolve($parts, $absolute); From 632bf01f016e59791a99951cfb24c2b63da1ca60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sun, 9 Jul 2017 13:09:09 +0300 Subject: [PATCH 2/8] Update project files --- .gitattributes | 2 +- .gitignore | 7 ++- .php_cs | 118 ++++++++++++++++++++++++++++++++++++++---------- .travis.yml | 20 ++++---- CHANGES.md | 4 ++ README.md | 12 ++--- apigen.neon | 12 ----- composer.json | 56 +++++++++++++++-------- sami_config.php | 26 +++++++++++ 9 files changed, 181 insertions(+), 76 deletions(-) delete mode 100644 apigen.neon create mode 100644 sami_config.php diff --git a/.gitattributes b/.gitattributes index ce7ef54..6a4f8d5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -7,5 +7,5 @@ tests export-ignore .gitignore export-ignore .php_cs export-ignore .travis.yml export-ignore -apigen.neon export-ignore phpunit.xml export-ignore +sami_config.php export-ignore diff --git a/.gitignore b/.gitignore index ef73e40..d6a14f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -.idea -api -coverage -vendor \ No newline at end of file +build/ +vendor/ +composer.lock diff --git a/.php_cs b/.php_cs index 9765e7e..8c61b21 100644 --- a/.php_cs +++ b/.php_cs @@ -1,31 +1,101 @@ in(__DIR__ . '/src') ->in(__DIR__ . '/tests'); -return Symfony\CS\Config\Config::create() - ->fixers([ - 'align_double_arrow', - 'concat_with_spaces', - 'ereg_to_preg', - 'multiline_spaces_before_semicolon', - 'newline_after_open_tag', - 'ordered_use', - 'php4_constructor', - 'php_unit_construct', - 'php_unit_strict', - 'short_array_syntax', - 'strict', - 'strict_param', +return \PhpCsFixer\Config::create() + ->setRules([ + '@PSR2' => true, - '-concat_without_spaces', - '-linefeed', - '-phpdoc_no_empty_return', - '-phpdoc_params', - '-phpdoc_separation', - '-pre_increment', - '-unalign_double_arrow', - '-unary_operators_spaces', + 'array_syntax' => [ + 'syntax' => 'short' + ], + 'binary_operator_spaces' => [ + 'align_double_arrow' => null, + 'align_equals' => false, + ], + 'blank_line_after_opening_tag' => true, + 'cast_spaces' => true, + 'combine_consecutive_unsets' => true, + 'concat_space' => [ + 'spacing' => 'one' + ], + 'declare_equal_normalize' => true, + 'dir_constant' => true, + 'ereg_to_preg' => true, + 'function_to_constant' => true, + 'function_typehint_space' => true, + 'hash_to_slash_comment' => true, + 'heredoc_to_nowdoc' => true, + 'include' => true, + 'is_null' => true, + 'lowercase_cast' => true, + 'magic_constant_casing' => true, + 'method_separation' => true, + 'modernize_types_casting' => true, + 'native_function_casing' => true, + 'new_with_braces' => true, + 'no_alias_functions' => true, + 'no_blank_lines_after_class_opening' => true, + 'no_blank_lines_after_phpdoc' => true, + 'no_empty_comment' => true, + 'no_empty_phpdoc' => true, + 'no_empty_statement' => true, + 'no_extra_consecutive_blank_lines' => true, + 'no_leading_import_slash' => true, + 'no_leading_namespace_whitespace' => true, + 'no_mixed_echo_print' => true, + 'no_multiline_whitespace_around_double_arrow' => true, + 'no_multiline_whitespace_before_semicolons' => true, + 'no_php4_constructor' => true, + 'no_short_bool_cast' => true, + 'no_singleline_whitespace_before_semicolons' => true, + 'no_spaces_around_offset' => true, + 'no_trailing_comma_in_list_call' => true, + 'no_trailing_comma_in_singleline_array' => true, + 'no_unneeded_control_parentheses' => true, + 'no_unused_imports' => true, + 'no_useless_return' => true, + 'no_whitespace_before_comma_in_array' => true, + 'no_whitespace_in_blank_line' => true, + 'non_printable_character' => true, + 'normalize_index_brace' => true, + 'object_operator_without_whitespace' => true, + 'ordered_class_elements' => [ + 'order' => ['use_trait', 'constant', 'property', 'construct', 'method'], + ], + 'ordered_imports' => true, + 'php_unit_construct' => true, + 'php_unit_dedicate_assert' => true, + 'php_unit_strict' => true, + 'phpdoc_add_missing_param_annotation' => true, + 'phpdoc_annotation_without_dot' => true, + 'phpdoc_indent' => true, + 'phpdoc_inline_tag' => true, + 'phpdoc_no_access' => true, + 'phpdoc_no_alias_tag' => true, + 'phpdoc_no_package' => true, + 'phpdoc_scalar' => true, + 'phpdoc_single_line_var_spacing' => true, + 'phpdoc_summary' => true, + 'phpdoc_trim' => true, + 'phpdoc_types' => true, + 'phpdoc_var_without_name' => true, + 'pow_to_exponentiation' => true, + 'psr4' => true, + 'return_type_declaration' => true, + 'self_accessor' => true, + 'short_scalar_cast' => true, + 'single_blank_line_before_namespace' => true, + 'single_quote' => true, + 'space_after_semicolon' => true, + 'standardize_not_equals' => true, + 'strict_comparison' => true, + 'strict_param' => true, + 'ternary_operator_spaces' => true, + 'trailing_comma_in_multiline_array' => true, + 'trim_array_spaces' => true, + 'whitespace_after_comma_in_array' => true, ]) - ->finder($finder); + ->setFinder($finder); diff --git a/.travis.yml b/.travis.yml index ee6a7b5..599b28f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,29 +1,31 @@ language: php sudo: false +dist: trusty php: - 5.6 - - 5.5 - - 5.4 - 7.0 + - 7.1 - hhvm cache: directories: - - vendor + - vendor before_install: - - composer self-update + - 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" install: - - composer require --no-update --no-interaction "phpunit/phpunit:*" "squizlabs/php_codesniffer:*" "fabpot/php-cs-fixer:*" - - travis_retry composer update --no-interaction --prefer-source + - travis_retry composer update -a --no-interaction - travis_retry wget https://scrutinizer-ci.com/ocular.phar script: - - vendor/bin/phpunit --coverage-clover=coverage.clover - vendor/bin/phpcs --standard=PSR2 src tests - - vendor/bin/php-cs-fixer fix --dry-run --diff + - 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 after_script: - - if [ -f coverage.clover ]; then php ocular.phar code-coverage:upload --format=php-clover coverage.clover; fi + - is_hhvm || php ocular.phar code-coverage:upload --format=php-clover coverage.clover diff --git a/CHANGES.md b/CHANGES.md index 39a9a68..cc3097c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Changelog # +## v1.2.0 (2017-07-09) ## + + * Increased minimum required PHP version to 5.6 + ## v1.1.2 (2015-08-22) ## * Slightly reworked how the paths are built diff --git a/README.md b/README.md index b423ca4..c068e00 100644 --- a/README.md +++ b/README.md @@ -15,18 +15,18 @@ case since it works by using the file system. This library simply combines and normalizes the paths using string handling. There is no requirement for the files or directories to be readable or even exist. -The API documentation, which can be generated using Apigen, can be read online -at: http://kit.riimu.net/api/pathjoin/ +The API documentation is available at: http://kit.riimu.net/api/pathjoin/ -[![Build Status](https://img.shields.io/travis/Riimu/Kit-PathJoin.svg?style=flat)](https://travis-ci.org/Riimu/Kit-PathJoin) -[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/Riimu/Kit-PathJoin.svg?style=flat)](https://scrutinizer-ci.com/g/Riimu/Kit-PathJoin/) -[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/Riimu/Kit-PathJoin.svg?style=flat)](https://scrutinizer-ci.com/g/Riimu/Kit-PathJoin/) +[![Travis](https://img.shields.io/travis/Riimu/Kit-PathJoin.svg?style=flat-square)](https://travis-ci.org/Riimu/Kit-PathJoin) +[![Scrutinizer](https://img.shields.io/scrutinizer/g/Riimu/Kit-PathJoin.svg?style=flat-square)](https://scrutinizer-ci.com/g/Riimu/Kit-PathJoin/) +[![Scrutinizer Coverage](https://img.shields.io/scrutinizer/coverage/g/Riimu/Kit-PathJoin.svg?style=flat-square)](https://scrutinizer-ci.com/g/Riimu/Kit-PathJoin/) +[![Packagist](https://img.shields.io/packagist/v/riimu/kit-pathjoin.svg?style=flat-square)](https://packagist.org/packages/riimu/kit-pathjoin) ## Requirements ## In order to use this library, the following requirements must be met: - * PHP version 5.4 + * PHP version 5.6 ## Installation ## diff --git a/apigen.neon b/apigen.neon deleted file mode 100644 index 53b1b90..0000000 --- a/apigen.neon +++ /dev/null @@ -1,12 +0,0 @@ -source: - - src - -destination: api -charset: - - UTF-8 - -main: Riimu\Kit\PathJoin -title: PathJoin -php: true -tree: true -templateTheme: bootstrap diff --git a/composer.json b/composer.json index 96d6dc2..505aeae 100644 --- a/composer.json +++ b/composer.json @@ -1,23 +1,39 @@ { - "name": "riimu/kit-pathjoin", - "type": "library", - "description": "Cross-platform library for normalizing and joining file system paths", - "homepage": "http://kit.riimu.net", - "keywords": ["normalize", "join", "file", "system", "path"], - "license": "MIT", - "authors": [ - { - "name": "Riikka Kalliomäki", - "email": "riikka.kalliomaki@gmail.com", - "homepage": "http://riimu.net" - } - ], - "require": { - "php": ">=5.4.0" - }, - "autoload": { - "psr-4": { - "Riimu\\Kit\\PathJoin\\": "src/" - } + "name": "riimu/kit-pathjoin", + "type": "library", + "description": "Cross-platform library for normalizing and joining file system paths", + "homepage": "http://kit.riimu.net", + "keywords": [ + "normalize", + "join", + "file", + "system", + "path" + ], + "license": "MIT", + "authors": [ + { + "name": "Riikka Kalliomäki", + "email": "riikka.kalliomaki@gmail.com", + "homepage": "http://riimu.net" } + ], + "require": { + "php": ">=5.4.0" + }, + "require-dev": { + "phpunit/phpunit": "^5.7 || ^6.2", + "squizlabs/php_codesniffer": "^3.0", + "friendsofphp/php-cs-fixer": "^2.3" + }, + "autoload": { + "psr-4": { + "Riimu\\Kit\\PathJoin\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "Riimu\\Kit\\PathJoin\\": "tests/tests/" + } + } } diff --git a/sami_config.php b/sami_config.php new file mode 100644 index 0000000..bd537af --- /dev/null +++ b/sami_config.php @@ -0,0 +1,26 @@ +files() + ->name('*.php') + ->in(__DIR__ . '/src'); + +$theme = getenv('SAMI_THEME'); +$settings = []; + +if ($theme) { + $settings['theme'] = basename($theme); + $settings['template_dirs'] = [dirname($theme)]; +} + +return new Sami($iterator, $settings + [ + 'title' => 'Kit PathJoin API', + 'build_dir' => __DIR__ . '/build/doc', + 'cache_dir' => __DIR__ . '/build/cache', + 'remote_repository' => new GitHubRemoteRepository('Riimu/Kit-PathJoin', __DIR__), + 'default_opened_level' => 3, +]); From b2d5de3477b6617e40efa67c431c81a7402de0fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sun, 9 Jul 2017 14:12:54 +0300 Subject: [PATCH 3/8] Update tests to work with latest PHPUnit --- CHANGES.md | 3 +++ src/Path.php | 4 +++- src/autoload.php | 10 ++++++---- tests/bootstrap.php | 2 +- tests/tests/PathTest.php | 8 +++++--- 5 files changed, 18 insertions(+), 9 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cc3097c..0cf4ebe 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -3,6 +3,9 @@ ## v1.2.0 (2017-07-09) ## * Increased minimum required PHP version to 5.6 + * Updated tests to work with PHPUnit 6 + * Updated travis build + * Slightly improved the bundled autoloader ## v1.1.2 (2015-08-22) ## diff --git a/src/Path.php b/src/Path.php index c6ab57c..5f34fd7 100644 --- a/src/Path.php +++ b/src/Path.php @@ -38,7 +38,7 @@ public static function normalize($path, $prependDrive = true) { $path = self::join((string) $path); - if ($path[0] === DIRECTORY_SEPARATOR && $prependDrive) { + if ($prependDrive && $path[0] === DIRECTORY_SEPARATOR) { return strstr(getcwd(), DIRECTORY_SEPARATOR, true) . $path; } @@ -94,6 +94,7 @@ private static function buildPath($root, array $parts) * Merges the paths and returns the individual parts. * @param string[] $paths Array of paths * @return string[] Parts in the paths merged into a single array + * @throws \InvalidArgumentException If no paths have been provided */ private static function getParts(array $paths) { @@ -171,5 +172,6 @@ private static function resolveParent(& $parts, $absolute) } $parts[] = '..'; + return null; } } diff --git a/src/autoload.php b/src/autoload.php index bc8572d..95cd7c6 100644 --- a/src/autoload.php +++ b/src/autoload.php @@ -1,10 +1,12 @@ DIRECTORY_SEPARATOR]) . '.php'; + if (file_exists($path)) { require $path; } diff --git a/tests/bootstrap.php b/tests/bootstrap.php index c174ede..d21c14d 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -1,3 +1,3 @@ * @copyright Copyright (c) 2014, Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ -class PathTest extends \PHPUnit_Framework_TestCase +class PathTest extends TestCase { public function testEmptyPathArray() { - $this->setExpectedException('InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); Path::join([]); } @@ -51,7 +53,7 @@ public function testDirectorySeparators() public function testInvalidColon() { - $this->setExpectedException('\InvalidArgumentException'); + $this->expectException(\InvalidArgumentException::class); Path::join('foo', 'C:\bar'); } From 1e821fd390287a5201e1016f25378fca14804fbb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sun, 9 Jul 2017 14:29:29 +0300 Subject: [PATCH 4/8] Only trim space characters --- CHANGES.md | 1 + src/Path.php | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 0cf4ebe..08bc910 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -2,6 +2,7 @@ ## v1.2.0 (2017-07-09) ## + * Minor changes to path joining logic * Increased minimum required PHP version to 5.6 * Updated tests to work with PHPUnit 6 * Updated travis build diff --git a/src/Path.php b/src/Path.php index 5f34fd7..8746b1c 100644 --- a/src/Path.php +++ b/src/Path.php @@ -102,7 +102,7 @@ private static function getParts(array $paths) throw new \InvalidArgumentException('You must provide at least one path'); } - return array_map('trim', explode('/', str_replace('\\', '/', implode('/', $paths)))); + return preg_split('# *[/\\\\]+ *#', trim(implode('/', $paths), ' ')); } /** From 6435f54baf85df0949471bb040e511143cd6b3b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sun, 9 Jul 2017 14:42:31 +0300 Subject: [PATCH 5/8] Normalise copyrights --- LICENSE | 2 +- README.md | 2 +- src/Path.php | 2 +- tests/tests/PathTest.php | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/LICENSE b/LICENSE index e48de6a..00b30de 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2014 - 2015 Riikka Kalliomäki +Copyright (c) 2014-2017 Riikka Kalliomäki Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index c068e00..7794d58 100644 --- a/README.md +++ b/README.md @@ -131,6 +131,6 @@ echo Path::normalize('/foo/bar', false) . PHP_EOL; // outputs '\foo\Bar' ## Credits ## -This library is copyright 2014 - 2015 to Riikka Kalliomäki. +This library is Copyright (c) 2014-2017 Riikka Kalliomäki. See LICENSE for license and copying information. diff --git a/src/Path.php b/src/Path.php index 8746b1c..189960b 100644 --- a/src/Path.php +++ b/src/Path.php @@ -5,7 +5,7 @@ /** * Cross-platform library for normalizing and joining file system paths. * @author Riikka Kalliomäki - * @copyright Copyright (c) 2014, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class Path diff --git a/tests/tests/PathTest.php b/tests/tests/PathTest.php index 2e14a6e..630e672 100644 --- a/tests/tests/PathTest.php +++ b/tests/tests/PathTest.php @@ -6,7 +6,7 @@ /** * @author Riikka Kalliomäki - * @copyright Copyright (c) 2014, Riikka Kalliomäki + * @copyright Copyright (c) 2014-2017 Riikka Kalliomäki * @license http://opensource.org/licenses/mit-license.php MIT License */ class PathTest extends TestCase From eb81f578cc49a0e240ccdfd2be441908cacec64a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sun, 9 Jul 2017 17:15:15 +0300 Subject: [PATCH 6/8] Make small code adjustments --- src/Path.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Path.php b/src/Path.php index 189960b..373a7c2 100644 --- a/src/Path.php +++ b/src/Path.php @@ -61,9 +61,10 @@ public static function normalize($path, $prependDrive = true) */ public static function join($paths) { + $arguments = is_array($paths) ? $paths : func_get_args(); $joins = []; - foreach (is_array($paths) ? $paths : func_get_args() as $path) { + foreach ($arguments as $path) { $joins[] = (string) $path; } @@ -163,15 +164,14 @@ private static function isValidPath($path) * Resolves the relative parent directory for the path. * @param string[] $parts Path parts to modify * @param bool $absolute True if dealing with absolute path, false if not - * @return string|null The removed parent or null if nothing was removed */ private static function resolveParent(& $parts, $absolute) { - if ($absolute || !in_array(end($parts), ['..', false], true)) { - return array_pop($parts); + if ($absolute || !in_array($parts[count($parts) - 1], ['..', false], true)) { + array_pop($parts); + return; } $parts[] = '..'; - return null; } } From f4bd624aa75c3b307869c65d9da529cab8a55705 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sun, 9 Jul 2017 17:23:02 +0300 Subject: [PATCH 7/8] Fix out of bounds error --- src/Path.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Path.php b/src/Path.php index 373a7c2..7e8cc82 100644 --- a/src/Path.php +++ b/src/Path.php @@ -167,7 +167,7 @@ private static function isValidPath($path) */ private static function resolveParent(& $parts, $absolute) { - if ($absolute || !in_array($parts[count($parts) - 1], ['..', false], true)) { + if ($absolute || ($parts && $parts[count($parts) - 1] !== '..')) { array_pop($parts); return; } From d04e2b9c2ecd310154d1a6737eb141f3af96a6b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Riikka=20Kalliom=C3=A4ki?= Date: Sun, 9 Jul 2017 17:32:14 +0300 Subject: [PATCH 8/8] Make small optimizations --- src/Path.php | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/Path.php b/src/Path.php index 7e8cc82..fb4e1ad 100644 --- a/src/Path.php +++ b/src/Path.php @@ -61,13 +61,7 @@ public static function normalize($path, $prependDrive = true) */ public static function join($paths) { - $arguments = is_array($paths) ? $paths : func_get_args(); - $joins = []; - - foreach ($arguments as $path) { - $joins[] = (string) $path; - } - + $joins = array_map('strval', is_array($paths) ? $paths : func_get_args()); $parts = self::getParts($joins); $absolute = self::isAbsolute($joins[0]); $root = $absolute ? array_shift($parts) . DIRECTORY_SEPARATOR : ''; @@ -165,9 +159,11 @@ private static function isValidPath($path) * @param string[] $parts Path parts to modify * @param bool $absolute True if dealing with absolute path, false if not */ - private static function resolveParent(& $parts, $absolute) + private static function resolveParent(array & $parts, $absolute) { - if ($absolute || ($parts && $parts[count($parts) - 1] !== '..')) { + $count = count($parts); + + if ($absolute || ($count > 0 && $parts[$count - 1] !== '..')) { array_pop($parts); return; }