Use fully qualified calls in hot classes

main
Jordi Boggiano 4 years ago
parent 00e1deec90
commit 81bf47ffa2
No known key found for this signature in database
GPG Key ID: 7BBD42C429EC80BC

@ -108,17 +108,17 @@ class Decisions implements \Iterator, \Countable
public function validOffset($queueOffset) public function validOffset($queueOffset)
{ {
return $queueOffset >= 0 && $queueOffset < count($this->decisionQueue); return $queueOffset >= 0 && $queueOffset < \count($this->decisionQueue);
} }
public function lastReason() public function lastReason()
{ {
return $this->decisionQueue[count($this->decisionQueue) - 1][self::DECISION_REASON]; return $this->decisionQueue[\count($this->decisionQueue) - 1][self::DECISION_REASON];
} }
public function lastLiteral() public function lastLiteral()
{ {
return $this->decisionQueue[count($this->decisionQueue) - 1][self::DECISION_LITERAL]; return $this->decisionQueue[\count($this->decisionQueue) - 1][self::DECISION_LITERAL];
} }
public function reset() public function reset()
@ -130,7 +130,7 @@ class Decisions implements \Iterator, \Countable
public function resetToOffset($offset) public function resetToOffset($offset)
{ {
while (count($this->decisionQueue) > $offset + 1) { while (\count($this->decisionQueue) > $offset + 1) {
$decision = array_pop($this->decisionQueue); $decision = array_pop($this->decisionQueue);
$this->decisionMap[abs($decision[self::DECISION_LITERAL])] = 0; $this->decisionMap[abs($decision[self::DECISION_LITERAL])] = 0;
} }
@ -144,7 +144,7 @@ class Decisions implements \Iterator, \Countable
public function count() public function count()
{ {
return count($this->decisionQueue); return \count($this->decisionQueue);
} }
public function rewind() public function rewind()
@ -174,7 +174,7 @@ class Decisions implements \Iterator, \Countable
public function isEmpty() public function isEmpty()
{ {
return count($this->decisionQueue) === 0; return \count($this->decisionQueue) === 0;
} }
protected function addDecision($literal, $level) protected function addDecision($literal, $level)

@ -60,7 +60,7 @@ class DefaultPolicy implements PolicyInterface
$sortedLiterals = $this->pruneRemoteAliases($pool, $sortedLiterals); $sortedLiterals = $this->pruneRemoteAliases($pool, $sortedLiterals);
} }
$selected = call_user_func_array('array_merge', $packages); $selected = \call_user_func_array('array_merge', $packages);
// now sort the result across all packages to respect replaces across packages // now sort the result across all packages to respect replaces across packages
usort($selected, function ($a, $b) use ($policy, $pool, $requiredPackage) { usort($selected, function ($a, $b) use ($policy, $pool, $requiredPackage) {

@ -64,7 +64,7 @@ class GenericRule extends Rule
public function isAssertion() public function isAssertion()
{ {
return 1 === count($this->literals); return 1 === \count($this->literals);
} }
/** /**

@ -33,7 +33,7 @@ class MultiConflictRule extends Rule
{ {
parent::__construct($reason, $reasonData); parent::__construct($reason, $reasonData);
if (count($literals) < 3) { if (\count($literals) < 3) {
throw new \RuntimeException("multi conflict rule requires at least 3 literals"); throw new \RuntimeException("multi conflict rule requires at least 3 literals");
} }

@ -71,7 +71,7 @@ class Pool implements \Countable
*/ */
public function count() public function count()
{ {
return count($this->packages); return \count($this->packages);
} }
/** /**
@ -189,6 +189,6 @@ class Pool implements \Countable
public function isUnacceptableFixedPackage(PackageInterface $package) public function isUnacceptableFixedPackage(PackageInterface $package)
{ {
return in_array($package, $this->unacceptableFixedPackages, true); return \in_array($package, $this->unacceptableFixedPackages, true);
} }
} }

@ -161,7 +161,7 @@ class PoolBuilder
// filter packages according to all the require statements collected for each package // filter packages according to all the require statements collected for each package
$nameConstraints = array(); $nameConstraints = array();
foreach ($this->nameConstraints as $name => $constraints) { foreach ($this->nameConstraints as $name => $constraints) {
if (is_array($constraints)) { if (\is_array($constraints)) {
$nameConstraints[$name] = MultiConstraint::create(array_values(array_unique($constraints)), false); $nameConstraints[$name] = MultiConstraint::create(array_values(array_unique($constraints)), false);
} }
} }
@ -275,9 +275,9 @@ class PoolBuilder
$linkConstraint = $link->getConstraint(); $linkConstraint = $link->getConstraint();
if ($linkConstraint && !($linkConstraint instanceof EmptyConstraint)) { if ($linkConstraint && !($linkConstraint instanceof EmptyConstraint)) {
if (!array_key_exists($require, $this->nameConstraints)) { if (!\array_key_exists($require, $this->nameConstraints)) {
$this->nameConstraints[$require] = array($linkConstraint); $this->nameConstraints[$require] = array($linkConstraint);
} elseif (is_array($this->nameConstraints[$require])) { } elseif (\is_array($this->nameConstraints[$require])) {
$this->nameConstraints[$require][] = $linkConstraint; $this->nameConstraints[$require][] = $linkConstraint;
} }
// else it is null and should stay null // else it is null and should stay null

@ -264,7 +264,7 @@ abstract class Rule
{ {
$prepared = array(); $prepared = array();
foreach ($packages as $index => $package) { foreach ($packages as $index => $package) {
if (!is_object($package)) { if (!\is_object($package)) {
$packages[$index] = $pool->literalToPackage($package); $packages[$index] = $pool->literalToPackage($package);
} }
} }

@ -76,7 +76,7 @@ class Rule2Literals extends Rule
} }
$literals = $rule->getLiterals(); $literals = $rule->getLiterals();
if (2 != count($literals)) { if (2 != \count($literals)) {
return false; return false;
} }

@ -65,7 +65,7 @@ class RuleSet implements \IteratorAggregate, \Countable
// Do not add if rule already exists // Do not add if rule already exists
if (isset($this->rulesByHash[$hash])) { if (isset($this->rulesByHash[$hash])) {
$potentialDuplicates = $this->rulesByHash[$hash]; $potentialDuplicates = $this->rulesByHash[$hash];
if (is_array($potentialDuplicates)) { if (\is_array($potentialDuplicates)) {
foreach ($potentialDuplicates as $potentialDuplicate) { foreach ($potentialDuplicates as $potentialDuplicate) {
if ($rule->equals($potentialDuplicate)) { if ($rule->equals($potentialDuplicate)) {
return; return;
@ -90,7 +90,7 @@ class RuleSet implements \IteratorAggregate, \Countable
if (!isset($this->rulesByHash[$hash])) { if (!isset($this->rulesByHash[$hash])) {
$this->rulesByHash[$hash] = $rule; $this->rulesByHash[$hash] = $rule;
} elseif (is_array($this->rulesByHash[$hash])) { } elseif (\is_array($this->rulesByHash[$hash])) {
$this->rulesByHash[$hash][] = $rule; $this->rulesByHash[$hash][] = $rule;
} else { } else {
$originalRule = $this->rulesByHash[$hash]; $originalRule = $this->rulesByHash[$hash];
@ -120,7 +120,7 @@ class RuleSet implements \IteratorAggregate, \Countable
public function getIteratorFor($types) public function getIteratorFor($types)
{ {
if (!is_array($types)) { if (!\is_array($types)) {
$types = array($types); $types = array($types);
} }
@ -136,7 +136,7 @@ class RuleSet implements \IteratorAggregate, \Countable
public function getIteratorWithout($types) public function getIteratorWithout($types)
{ {
if (!is_array($types)) { if (!\is_array($types)) {
$types = array($types); $types = array($types);
} }

@ -120,7 +120,7 @@ class RuleSetGenerator
$literals[] = -$package->id; $literals[] = -$package->id;
} }
if (count($literals) == 2) { if (\count($literals) == 2) {
return new Rule2Literals($literals[0], $literals[1], $reason, $reasonData); return new Rule2Literals($literals[0], $literals[1], $reason, $reasonData);
} }
@ -207,7 +207,7 @@ class RuleSetGenerator
} }
foreach ($this->addedPackagesByNames as $name => $packages) { foreach ($this->addedPackagesByNames as $name => $packages) {
if (count($packages) > 1) { if (\count($packages) > 1) {
$reason = Rule::RULE_PACKAGE_SAME_NAME; $reason = Rule::RULE_PACKAGE_SAME_NAME;
$this->addRule(RuleSet::TYPE_PACKAGE, $this->createMultiConflictRule($packages, $reason, $name)); $this->addRule(RuleSet::TYPE_PACKAGE, $this->createMultiConflictRule($packages, $reason, $name));
} }

@ -51,7 +51,7 @@ class RuleSetIterator implements \Iterator
return; return;
} }
if ($this->currentOffset >= count($this->rules[$this->currentType])) { if ($this->currentOffset >= \count($this->rules[$this->currentType])) {
$this->currentOffset = 0; $this->currentOffset = 0;
do { do {
@ -63,7 +63,7 @@ class RuleSetIterator implements \Iterator
} }
$this->currentType = $this->types[$this->currentTypeOffset]; $this->currentType = $this->types[$this->currentTypeOffset];
} while (isset($this->types[$this->currentTypeOffset]) && !count($this->rules[$this->currentType])); } while (isset($this->types[$this->currentTypeOffset]) && !\count($this->rules[$this->currentType]));
} }
} }
@ -83,7 +83,7 @@ class RuleSetIterator implements \Iterator
} }
$this->currentType = $this->types[$this->currentTypeOffset]; $this->currentType = $this->types[$this->currentTypeOffset];
} while (isset($this->types[$this->currentTypeOffset]) && !count($this->rules[$this->currentType])); } while (isset($this->types[$this->currentTypeOffset]) && !\count($this->rules[$this->currentType]));
} }
public function valid() public function valid()

@ -37,7 +37,7 @@ class RuleWatchNode
$literals = $rule->getLiterals(); $literals = $rule->getLiterals();
$literalCount = count($literals); $literalCount = \count($literals);
$this->watch1 = $literalCount > 0 ? $literals[0] : 0; $this->watch1 = $literalCount > 0 ? $literals[0] : 0;
$this->watch2 = $literalCount > 1 ? $literals[1] : 0; $this->watch2 = $literalCount > 1 ? $literals[1] : 0;
} }
@ -55,7 +55,7 @@ class RuleWatchNode
$literals = $this->rule->getLiterals(); $literals = $this->rule->getLiterals();
// if there are only 2 elements, both are being watched anyway // if there are only 2 elements, both are being watched anyway
if (count($literals) < 3 || $this->rule instanceof MultiConflictRule) { if (\count($literals) < 3 || $this->rule instanceof MultiConflictRule) {
return; return;
} }

@ -75,7 +75,7 @@ class Solver
*/ */
public function getRuleSetSize() public function getRuleSetSize()
{ {
return count($this->rules); return \count($this->rules);
} }
public function getPool() public function getPool()
@ -87,9 +87,9 @@ class Solver
private function makeAssertionRuleDecisions() private function makeAssertionRuleDecisions()
{ {
$decisionStart = count($this->decisions) - 1; $decisionStart = \count($this->decisions) - 1;
$rulesCount = count($this->rules); $rulesCount = \count($this->rules);
for ($ruleIndex = 0; $ruleIndex < $rulesCount; $ruleIndex++) { for ($ruleIndex = 0; $ruleIndex < $rulesCount; $ruleIndex++) {
$rule = $this->rules->ruleById[$ruleIndex]; $rule = $this->rules->ruleById[$ruleIndex];
@ -269,10 +269,10 @@ class Solver
} }
$this->decisions->revertLast(); $this->decisions->revertLast();
$this->propagateIndex = count($this->decisions); $this->propagateIndex = \count($this->decisions);
} }
while (!empty($this->branches) && $this->branches[count($this->branches) - 1][self::BRANCH_LEVEL] >= $level) { while (!empty($this->branches) && $this->branches[\count($this->branches) - 1][self::BRANCH_LEVEL] >= $level) {
array_pop($this->branches); array_pop($this->branches);
} }
} }
@ -357,7 +357,7 @@ class Solver
$selectedLiteral = array_shift($literals); $selectedLiteral = array_shift($literals);
// if there are multiple candidates, then branch // if there are multiple candidates, then branch
if (count($literals)) { if (\count($literals)) {
$this->branches[] = array($literals, $level); $this->branches[] = array($literals, $level);
} }
@ -378,12 +378,12 @@ class Solver
$seen = array(); $seen = array();
$learnedLiterals = array(null); $learnedLiterals = array(null);
$decisionId = count($this->decisions); $decisionId = \count($this->decisions);
$this->learnedPool[] = array(); $this->learnedPool[] = array();
while (true) { while (true) {
$this->learnedPool[count($this->learnedPool) - 1][] = $rule; $this->learnedPool[\count($this->learnedPool) - 1][] = $rule;
foreach ($rule->getLiterals() as $literal) { foreach ($rule->getLiterals() as $literal) {
// skip the one true literal // skip the one true literal
@ -466,7 +466,7 @@ class Solver
$rule = $decision[Decisions::DECISION_REASON]; $rule = $decision[Decisions::DECISION_REASON];
} }
$why = count($this->learnedPool) - 1; $why = \count($this->learnedPool) - 1;
if (!$learnedLiterals[0]) { if (!$learnedLiterals[0]) {
throw new SolverBugException( throw new SolverBugException(
@ -647,7 +647,7 @@ class Solver
} }
} }
if ($noneSatisfied && count($decisionQueue)) { if ($noneSatisfied && \count($decisionQueue)) {
// if any of the options in the decision queue are fixed, only use those // if any of the options in the decision queue are fixed, only use those
$prunedQueue = array(); $prunedQueue = array();
foreach ($decisionQueue as $literal) { foreach ($decisionQueue as $literal) {
@ -660,7 +660,7 @@ class Solver
} }
} }
if ($noneSatisfied && count($decisionQueue)) { if ($noneSatisfied && \count($decisionQueue)) {
$oLevel = $level; $oLevel = $level;
$level = $this->selectAndInstall($level, $decisionQueue, $rule); $level = $this->selectAndInstall($level, $decisionQueue, $rule);
@ -687,7 +687,7 @@ class Solver
$systemLevel = $level; $systemLevel = $level;
} }
$rulesCount = count($this->rules); $rulesCount = \count($this->rules);
$pass = 1; $pass = 1;
$this->io->writeError('Looking at all rules.', true, IOInterface::DEBUG); $this->io->writeError('Looking at all rules.', true, IOInterface::DEBUG);
@ -734,7 +734,7 @@ class Solver
} }
// need to have at least 2 item to pick from // need to have at least 2 item to pick from
if (count($decisionQueue) < 2) { if (\count($decisionQueue) < 2) {
continue; continue;
} }
@ -745,7 +745,7 @@ class Solver
} }
// something changed, so look at all rules again // something changed, so look at all rules again
$rulesCount = count($this->rules); $rulesCount = \count($this->rules);
$n = -1; $n = -1;
} }
@ -754,13 +754,13 @@ class Solver
} }
// minimization step // minimization step
if (count($this->branches)) { if (\count($this->branches)) {
$lastLiteral = null; $lastLiteral = null;
$lastLevel = null; $lastLevel = null;
$lastBranchIndex = 0; $lastBranchIndex = 0;
$lastBranchOffset = 0; $lastBranchOffset = 0;
for ($i = count($this->branches) - 1; $i >= 0; $i--) { for ($i = \count($this->branches) - 1; $i >= 0; $i--) {
list($literals, $l) = $this->branches[$i]; list($literals, $l) = $this->branches[$i];
foreach ($literals as $offset => $literal) { foreach ($literals as $offset => $literal) {

@ -179,7 +179,7 @@ class AliasPackage extends BasePackage implements CompletePackageInterface
$prettyVersion = $this->aliasOf->getPrettyVersion(); $prettyVersion = $this->aliasOf->getPrettyVersion();
} }
if (in_array($linkType, array('conflicts', 'provides', 'replaces'), true)) { if (\in_array($linkType, array('conflicts', 'provides', 'replaces'), true)) {
$newLinks = array(); $newLinks = array();
foreach ($links as $link) { foreach ($links as $link) {
// link is self.version, but must be replacing also the replaced version // link is self.version, but must be replacing also the replaced version

@ -215,7 +215,7 @@ abstract class BasePackage implements PackageInterface
public function getFullPrettyVersion($truncate = true, $displayMode = PackageInterface::DISPLAY_SOURCE_REF_IF_DEV) public function getFullPrettyVersion($truncate = true, $displayMode = PackageInterface::DISPLAY_SOURCE_REF_IF_DEV)
{ {
if ($displayMode === PackageInterface::DISPLAY_SOURCE_REF_IF_DEV && if ($displayMode === PackageInterface::DISPLAY_SOURCE_REF_IF_DEV &&
(!$this->isDev() || !in_array($this->getSourceType(), array('hg', 'git'))) (!$this->isDev() || !\in_array($this->getSourceType(), array('hg', 'git')))
) { ) {
return $this->getPrettyVersion(); return $this->getPrettyVersion();
} }
@ -233,7 +233,7 @@ abstract class BasePackage implements PackageInterface
} }
// if source reference is a sha1 hash -- truncate // if source reference is a sha1 hash -- truncate
if ($truncate && strlen($reference) === 40) { if ($truncate && \strlen($reference) === 40) {
return $this->getPrettyVersion() . ' ' . substr($reference, 0, 7); return $this->getPrettyVersion() . ' ' . substr($reference, 0, 7);
} }

@ -213,6 +213,6 @@ class CompletePackage extends Package implements CompletePackageInterface
*/ */
public function getReplacementPackage() public function getReplacementPackage()
{ {
return is_string($this->abandoned) ? $this->abandoned : null; return \is_string($this->abandoned) ? $this->abandoned : null;
} }
} }

@ -109,7 +109,7 @@ class ArrayDumper
$data = $this->dumpValues($package, $keys, $data); $data = $this->dumpValues($package, $keys, $data);
if (isset($data['keywords']) && is_array($data['keywords'])) { if (isset($data['keywords']) && \is_array($data['keywords'])) {
sort($data['keywords']); sort($data['keywords']);
} }
@ -125,7 +125,7 @@ class ArrayDumper
} }
} }
if (count($package->getTransportOptions()) > 0) { if (\count($package->getTransportOptions()) > 0) {
$data['transport-options'] = $package->getTransportOptions(); $data['transport-options'] = $package->getTransportOptions();
} }
@ -142,7 +142,7 @@ class ArrayDumper
$getter = 'get'.ucfirst($method); $getter = 'get'.ucfirst($method);
$value = $package->$getter(); $value = $package->$getter();
if (null !== $value && !(is_array($value) && 0 === count($value))) { if (null !== $value && !(\is_array($value) && 0 === \count($value))) {
$data[$key] = $value; $data[$key] = $value;
} }
} }

@ -109,7 +109,7 @@ class ArrayLoader implements LoaderInterface
$package->setTargetDir($config['target-dir']); $package->setTargetDir($config['target-dir']);
} }
if (isset($config['extra']) && is_array($config['extra'])) { if (isset($config['extra']) && \is_array($config['extra'])) {
$package->setExtra($config['extra']); $package->setExtra($config['extra']);
} }
@ -159,7 +159,7 @@ class ArrayLoader implements LoaderInterface
} }
} }
if (isset($config['suggest']) && is_array($config['suggest'])) { if (isset($config['suggest']) && \is_array($config['suggest'])) {
foreach ($config['suggest'] as $target => $reason) { foreach ($config['suggest'] as $target => $reason) {
if ('self.version' === trim($reason)) { if ('self.version' === trim($reason)) {
$config['suggest'][$target] = $package->getPrettyVersion(); $config['suggest'][$target] = $package->getPrettyVersion();
@ -199,7 +199,7 @@ class ArrayLoader implements LoaderInterface
} }
if ($package instanceof Package\CompletePackageInterface) { if ($package instanceof Package\CompletePackageInterface) {
if (isset($config['scripts']) && is_array($config['scripts'])) { if (isset($config['scripts']) && \is_array($config['scripts'])) {
foreach ($config['scripts'] as $event => $listeners) { foreach ($config['scripts'] as $event => $listeners) {
$config['scripts'][$event] = (array) $listeners; $config['scripts'][$event] = (array) $listeners;
} }
@ -209,23 +209,23 @@ class ArrayLoader implements LoaderInterface
$package->setScripts($config['scripts']); $package->setScripts($config['scripts']);
} }
if (!empty($config['description']) && is_string($config['description'])) { if (!empty($config['description']) && \is_string($config['description'])) {
$package->setDescription($config['description']); $package->setDescription($config['description']);
} }
if (!empty($config['homepage']) && is_string($config['homepage'])) { if (!empty($config['homepage']) && \is_string($config['homepage'])) {
$package->setHomepage($config['homepage']); $package->setHomepage($config['homepage']);
} }
if (!empty($config['keywords']) && is_array($config['keywords'])) { if (!empty($config['keywords']) && \is_array($config['keywords'])) {
$package->setKeywords($config['keywords']); $package->setKeywords($config['keywords']);
} }
if (!empty($config['license'])) { if (!empty($config['license'])) {
$package->setLicense(is_array($config['license']) ? $config['license'] : array($config['license'])); $package->setLicense(\is_array($config['license']) ? $config['license'] : array($config['license']));
} }
if (!empty($config['authors']) && is_array($config['authors'])) { if (!empty($config['authors']) && \is_array($config['authors'])) {
$package->setAuthors($config['authors']); $package->setAuthors($config['authors']);
} }
@ -233,7 +233,7 @@ class ArrayLoader implements LoaderInterface
$package->setSupport($config['support']); $package->setSupport($config['support']);
} }
if (!empty($config['funding']) && is_array($config['funding'])) { if (!empty($config['funding']) && \is_array($config['funding'])) {
$package->setFunding($config['funding']); $package->setFunding($config['funding']);
} }
@ -307,8 +307,8 @@ class ArrayLoader implements LoaderInterface
private function createLink($source, $sourceVersion, $description, $target, $prettyConstraint) private function createLink($source, $sourceVersion, $description, $target, $prettyConstraint)
{ {
if (!is_string($prettyConstraint)) { if (!\is_string($prettyConstraint)) {
throw new \UnexpectedValueException('Link constraint in '.$source.' '.$description.' > '.$target.' should be a string, got '.gettype($prettyConstraint) . ' (' . var_export($prettyConstraint, true) . ')'); throw new \UnexpectedValueException('Link constraint in '.$source.' '.$description.' > '.$target.' should be a string, got '.\gettype($prettyConstraint) . ' (' . var_export($prettyConstraint, true) . ')');
} }
if ('self.version' === $prettyConstraint) { if ('self.version' === $prettyConstraint) {
$parsedConstraint = $this->versionParser->parseConstraints($sourceVersion); $parsedConstraint = $this->versionParser->parseConstraints($sourceVersion);
@ -331,7 +331,7 @@ class ArrayLoader implements LoaderInterface
return; return;
} }
if (isset($config['extra']['branch-alias']) && is_array($config['extra']['branch-alias'])) { if (isset($config['extra']['branch-alias']) && \is_array($config['extra']['branch-alias'])) {
foreach ($config['extra']['branch-alias'] as $sourceBranch => $targetBranch) { foreach ($config['extra']['branch-alias'] as $sourceBranch => $targetBranch) {
// ensure it is an alias to a -dev package // ensure it is an alias to a -dev package
if ('-dev' !== substr($targetBranch, -4)) { if ('-dev' !== substr($targetBranch, -4)) {
@ -361,7 +361,7 @@ class ArrayLoader implements LoaderInterface
} }
} }
if (in_array($config['version'], array('dev-master', 'dev-default', 'dev-trunk'), true)) { if (\in_array($config['version'], array('dev-master', 'dev-default', 'dev-trunk'), true)) {
return VersionParser::DEV_MASTER_ALIAS; return VersionParser::DEV_MASTER_ALIAS;
} }
} }

@ -619,7 +619,7 @@ class Package extends BasePackage
} else { } else {
continue; continue;
} }
if (!in_array($mirrorUrl, $urls)) { if (!\in_array($mirrorUrl, $urls)) {
$func = $mirror['preferred'] ? 'array_unshift' : 'array_push'; $func = $mirror['preferred'] ? 'array_unshift' : 'array_push';
$func($urls, $mirrorUrl); $func($urls, $mirrorUrl);
} }

@ -58,7 +58,7 @@ class Filesystem
->depth(0) ->depth(0)
->in($dir); ->in($dir);
return count($finder) === 0; return \count($finder) === 0;
} }
public function emptyDirectory($dir, $ensureDirectoryExists = true) public function emptyDirectory($dir, $ensureDirectoryExists = true)
@ -116,7 +116,7 @@ class Filesystem
throw new \RuntimeException('Aborting an attempted deletion of '.$directory.', this was probably not intended, if it is a real use case please report it.'); throw new \RuntimeException('Aborting an attempted deletion of '.$directory.', this was probably not intended, if it is a real use case please report it.');
} }
if (!function_exists('proc_open')) { if (!\function_exists('proc_open')) {
return $this->removeDirectoryPhp($directory); return $this->removeDirectoryPhp($directory);
} }
@ -311,7 +311,7 @@ class Filesystem
return; return;
} }
if (!function_exists('proc_open')) { if (!\function_exists('proc_open')) {
$this->copyThenRemove($source, $target); $this->copyThenRemove($source, $target);
return; return;
@ -369,13 +369,13 @@ class Filesystem
$from = rtrim($from, '/') . '/dummy_file'; $from = rtrim($from, '/') . '/dummy_file';
} }
if (dirname($from) === dirname($to)) { if (\dirname($from) === \dirname($to)) {
return './'.basename($to); return './'.basename($to);
} }
$commonPath = $to; $commonPath = $to;
while (strpos($from.'/', $commonPath.'/') !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath)) { while (strpos($from.'/', $commonPath.'/') !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath)) {
$commonPath = strtr(dirname($commonPath), '\\', '/'); $commonPath = strtr(\dirname($commonPath), '\\', '/');
} }
if (0 !== strpos($from, $commonPath) || '/' === $commonPath) { if (0 !== strpos($from, $commonPath) || '/' === $commonPath) {
@ -383,10 +383,10 @@ class Filesystem
} }
$commonPath = rtrim($commonPath, '/') . '/'; $commonPath = rtrim($commonPath, '/') . '/';
$sourcePathDepth = substr_count(substr($from, strlen($commonPath)), '/'); $sourcePathDepth = substr_count(substr($from, \strlen($commonPath)), '/');
$commonPathCode = str_repeat('../', $sourcePathDepth); $commonPathCode = str_repeat('../', $sourcePathDepth);
return ($commonPathCode . substr($to, strlen($commonPath))) ?: './'; return ($commonPathCode . substr($to, \strlen($commonPath))) ?: './';
} }
/** /**
@ -414,7 +414,7 @@ class Filesystem
$commonPath = $to; $commonPath = $to;
while (strpos($from.'/', $commonPath.'/') !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) { while (strpos($from.'/', $commonPath.'/') !== 0 && '/' !== $commonPath && !preg_match('{^[a-z]:/?$}i', $commonPath) && '.' !== $commonPath) {
$commonPath = strtr(dirname($commonPath), '\\', '/'); $commonPath = strtr(\dirname($commonPath), '\\', '/');
} }
if (0 !== strpos($from, $commonPath) || '/' === $commonPath || '.' === $commonPath) { if (0 !== strpos($from, $commonPath) || '/' === $commonPath || '.' === $commonPath) {
@ -423,17 +423,17 @@ class Filesystem
$commonPath = rtrim($commonPath, '/') . '/'; $commonPath = rtrim($commonPath, '/') . '/';
if (strpos($to, $from.'/') === 0) { if (strpos($to, $from.'/') === 0) {
return '__DIR__ . '.var_export(substr($to, strlen($from)), true); return '__DIR__ . '.var_export(substr($to, \strlen($from)), true);
} }
$sourcePathDepth = substr_count(substr($from, strlen($commonPath)), '/') + $directories; $sourcePathDepth = substr_count(substr($from, \strlen($commonPath)), '/') + $directories;
if ($staticCode) { if ($staticCode) {
$commonPathCode = "__DIR__ . '".str_repeat('/..', $sourcePathDepth)."'"; $commonPathCode = "__DIR__ . '".str_repeat('/..', $sourcePathDepth)."'";
} else { } else {
$commonPathCode = str_repeat('dirname(', $sourcePathDepth).'__DIR__'.str_repeat(')', $sourcePathDepth); $commonPathCode = str_repeat('dirname(', $sourcePathDepth).'__DIR__'.str_repeat(')', $sourcePathDepth);
} }
$relTarget = substr($to, strlen($commonPath)); $relTarget = substr($to, \strlen($commonPath));
return $commonPathCode . (strlen($relTarget) ? '.' . var_export('/' . $relTarget, true) : ''); return $commonPathCode . (\strlen($relTarget) ? '.' . var_export('/' . $relTarget, true) : '');
} }
/** /**
@ -484,7 +484,7 @@ class Filesystem
// extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive: // extract a prefix being a protocol://, protocol:, protocol://drive: or simply drive:
if (preg_match('{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix', $path, $match)) { if (preg_match('{^( [0-9a-z]{2,}+: (?: // (?: [a-z]: )? )? | [a-z]: )}ix', $path, $match)) {
$prefix = $match[1]; $prefix = $match[1];
$path = substr($path, strlen($prefix)); $path = substr($path, \strlen($prefix));
} }
if (substr($path, 0, 1) === '/') { if (substr($path, 0, 1) === '/') {
@ -579,7 +579,7 @@ class Filesystem
$cwd = getcwd(); $cwd = getcwd();
$relativePath = $this->findShortestPath($link, $target); $relativePath = $this->findShortestPath($link, $target);
chdir(dirname($link)); chdir(\dirname($link));
$result = @symlink($relativePath, $link); $result = @symlink($relativePath, $link);
chdir($cwd); chdir($cwd);
@ -632,7 +632,7 @@ class Filesystem
$resolved = rtrim($pathname, '/'); $resolved = rtrim($pathname, '/');
if (!strlen($resolved)) { if (!\strlen($resolved)) {
return $pathname; return $pathname;
} }

@ -55,7 +55,7 @@ class Platform
return $home; return $home;
} }
if (function_exists('posix_getuid') && function_exists('posix_getpwuid')) { if (\function_exists('posix_getuid') && \function_exists('posix_getpwuid')) {
$info = posix_getpwuid(posix_getuid()); $info = posix_getpwuid(posix_getuid());
return $info['dir']; return $info['dir'];
@ -69,7 +69,7 @@ class Platform
*/ */
public static function isWindows() public static function isWindows()
{ {
return defined('PHP_WINDOWS_VERSION_BUILD'); return \defined('PHP_WINDOWS_VERSION_BUILD');
} }
/** /**
@ -80,13 +80,13 @@ class Platform
{ {
static $useMbString = null; static $useMbString = null;
if (null === $useMbString) { if (null === $useMbString) {
$useMbString = function_exists('mb_strlen') && ini_get('mbstring.func_overload'); $useMbString = \function_exists('mb_strlen') && ini_get('mbstring.func_overload');
} }
if ($useMbString) { if ($useMbString) {
return mb_strlen($str, '8bit'); return mb_strlen($str, '8bit');
} }
return strlen($str); return \strlen($str);
} }
} }

Loading…
Cancel
Save