Skip to content

Commit

Permalink
Add missing typehints and return types
Browse files Browse the repository at this point in the history
  • Loading branch information
laurie.plociennik authored and laurieplo committed Oct 28, 2018
1 parent 137b126 commit 1952e7e
Show file tree
Hide file tree
Showing 65 changed files with 89 additions and 101 deletions.
4 changes: 2 additions & 2 deletions src/Collection/FilesCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function notPaths(array $pattern): self

public function extensions(array $extensions): self
{
if (!count($extensions)) {
if (!\count($extensions)) {
return new self();
}

Expand Down Expand Up @@ -184,7 +184,7 @@ public function filterByFileList(Traversable $fileList): self
}, iterator_to_array($fileList));

return $this->filter(function (SplFileInfo $file) use ($allowedFiles) {
return in_array($file->getPathname(), $allowedFiles, true);
return \in_array($file->getPathname(), $allowedFiles, true);
});
}

Expand Down
4 changes: 2 additions & 2 deletions src/Collection/ProcessArgumentsCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function addOptionalArgumentWithSeparatedValue(string $argument, $value)

public function addOptionalCommaSeparatedArgument(string $argument, array $values, string $delimiter = ',')
{
if (!count($values)) {
if (!\count($values)) {
return;
}

Expand All @@ -65,7 +65,7 @@ public function addArgumentArrayWithSeparatedValue(string $argument, array $valu

public function addSeparatedArgumentArray(string $argument, array $values)
{
if (!count($values)) {
if (!\count($values)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Collection/TaskResultCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class TaskResultCollection extends ArrayCollection

public function isPassed(): bool
{
return TaskResult::PASSED == $this->getResultCode();
return TaskResult::PASSED === $this->getResultCode();
}

public function isFailed(): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Collection/TasksCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function filterByTestSuite(TestSuiteInterface $testSuite = null): self
}

return $this->filter(function (TaskInterface $task) use ($testSuite) {
return in_array($task->getName(), $testSuite->getTaskNames(), true);
return \in_array($task->getName(), $testSuite->getTaskNames(), true);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Composer/DevelopmentIntegrator.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ public static function integrate(Event $event)

private static function noramlizePath(string $path): string
{
return strtr($path, '/', DIRECTORY_SEPARATOR);
return str_replace('/', DIRECTORY_SEPARATOR, $path);
}
}
2 changes: 1 addition & 1 deletion src/Composer/GrumPHPPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function runScheduledTasks(Event $event)

protected function guardIsGrumPhpPackage(PackageInterface $package): bool
{
return self::PACKAGE_NAME == $package->getName();
return self::PACKAGE_NAME === $package->getName();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Compiler/ExtensionCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class ExtensionCompilerPass implements CompilerPassInterface
public function process(ContainerBuilder $container)
{
$extensions = $container->getParameter('extensions');
$extensions = is_array($extensions) ? $extensions : [];
$extensions = \is_array($extensions) ? $extensions : [];
foreach ($extensions as $extensionClass) {
if (!class_exists($extensionClass)) {
throw new RuntimeException(sprintf('Invalid extension class specified: %s', $extensionClass));
Expand Down
6 changes: 3 additions & 3 deletions src/Configuration/Compiler/TaskCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function process(ContainerBuilder $container)
foreach ($taggedServices as $id => $tags) {
$taskTag = $this->getTaskTag($tags);
$configKey = $taskTag['config'];
if (in_array($configKey, $tasksRegistered, true)) {
if (\in_array($configKey, $tasksRegistered, true)) {
throw new RuntimeException(
sprintf('The name of a task should be unique. Duplicate found: %s', $configKey)
);
Expand All @@ -41,7 +41,7 @@ public function process(ContainerBuilder $container)
}

// Load configuration and metadata:
$taskConfig = is_array($configuration[$configKey]) ? $configuration[$configKey] : [];
$taskConfig = \is_array($configuration[$configKey]) ? $configuration[$configKey] : [];
$tasksMetadata[$configKey] = $this->parseTaskMetadata($taskConfig);

// The metadata can't be part of the actual configuration.
Expand Down Expand Up @@ -76,7 +76,7 @@ private function parseTaskMetadata(array $configuration): array
'blocking' => true,
]);

$metadata = isset($configuration['metadata']) ? $configuration['metadata'] : [];
$metadata = $configuration['metadata'] ?? [];

return $resolver->resolve($metadata);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/Compiler/TestSuiteCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private function createOptionsResolver(array $registeredTasks): OptionsResolver
$options->setAllowedTypes('tasks', ['array']);
$options->setAllowedValues('tasks', function (array $value) use ($registeredTasks) {
foreach ($value as $task) {
if (!in_array($task, $registeredTasks, true)) {
if (!\in_array($task, $registeredTasks, true)) {
throw new InvalidOptionsException(sprintf(
'The testsuite option "tasks" contains the unknow task "%s". Expected one of %s',
$task,
Expand Down
2 changes: 1 addition & 1 deletion src/Configuration/GrumPHP.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public function getAsciiContentPath(string $resource)
}

// Deal with multiple ascii files by returning one at random.
if (is_array($paths[$resource])) {
if (\is_array($paths[$resource])) {
shuffle($paths[$resource]);
return reset($paths[$resource]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Console/Command/Git/InitCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected function useExoticConfigFile()
{
try {
$configPath = $this->paths()->getAbsolutePath($this->input->getOption('config'));
if ($configPath != $this->paths()->getDefaultConfigPath()) {
if ($configPath !== $this->paths()->getDefaultConfigPath()) {
return $this->paths()->getRelativeProjectPath($configPath);
}
} catch (FileNotFoundException $e) {
Expand Down
4 changes: 2 additions & 2 deletions src/Event/Subscriber/StashUnstagedChangesSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function handleErrors()
private function doSaveStash()
{
$pending = $this->repository->getWorkingCopy()->getDiffPending();
if (!count($pending->getFiles())) {
if (!\count($pending->getFiles())) {
return;
}

Expand Down Expand Up @@ -168,7 +168,7 @@ private function registerShutdownHandler()
}

// Don't fail on non-blcoking errors!
if (in_array($error['type'], [E_DEPRECATED, E_USER_DEPRECATED, E_CORE_WARNING, E_CORE_ERROR], true)) {
if (\in_array($error['type'], [E_DEPRECATED, E_USER_DEPRECATED, E_CORE_WARNING, E_CORE_ERROR], true)) {
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/Formatter/GitBlacklistFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private function formatOutput(string $output): string
{
$result = static::RESET_COLOR;
foreach (array_filter(explode("\n", $output)) as $lineNumber => $line) {
$result .= preg_match('/^[0-9]+/', $line) ? $this->trimOutputLine($line, (int) $lineNumber) : $line;
$result .= preg_match('/^\d+/', $line) ? $this->trimOutputLine($line, (int) $lineNumber) : $line;
$result .= PHP_EOL;
}

Expand All @@ -54,7 +54,7 @@ private function formatOutput(string $output): string

private function trimOutputLine(string $line, int $lineNumber): string
{
if (strlen($line) < 80) {
if (\strlen($line) < 80) {
return $line;
}

Expand All @@ -66,14 +66,14 @@ private function trimOutputLine(string $line, int $lineNumber): string
//iterate over all WORD_COLORs and save the positions into $positionsWordColor
while (false !== ($lastPos = mb_strpos($line, static::WORD_COLOR, $lastPos))) {
$positionsWordColor[] = $lastPos;
$lastPos = $lastPos + mb_strlen(static::WORD_COLOR);
$lastPos += mb_strlen(static::WORD_COLOR);
}
$lastPos = 0;

//iterate over all RESET_COLORs and save the positions into $positionsResetColor
while (false !== ($lastPos = mb_strpos($line, static::RESET_COLOR, $lastPos))) {
$positionsResetColor[] = $lastPos;
$lastPos = $lastPos + mb_strlen(static::RESET_COLOR);
$lastPos += mb_strlen(static::RESET_COLOR);
}

foreach ($positionsWordColor as $pos) {
Expand Down
2 changes: 1 addition & 1 deletion src/Formatter/PhpCsFixerFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function formatJsonResponse(array $json): string
{
$formatted = [];
foreach ($json['files'] as $file) {
if (!is_array($file) || !isset($file['name'])) {
if (!\is_array($file) || !isset($file['name'])) {
$formatted[] = 'Invalid file: '.print_r($file, true);
continue;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Formatter/PhpcsFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public function format(Process $process): string
public function getSuggestedFilesFromJson(array $json): array
{
$suggestedFiles = [];
if (!isset($json['totals'], $json['totals']['fixable']) || $json['totals']['fixable'] == 0) {
if (!isset($json['totals']['fixable']) || $json['totals']['fixable'] === 0) {
return $suggestedFiles;
}
foreach ($json['files'] as $absolutePath => $data) {
if (!is_array($data) || empty($data['messages'])) {
if (!\is_array($data) || empty($data['messages'])) {
continue;
}
foreach ($data['messages'] as $message) {
if (is_array($message) && $message['fixable']) {
if (\is_array($message) && $message['fixable']) {
$suggestedFiles[] = $absolutePath;
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Linter/Xml/XmlLinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function isInstalled(): bool
{
$extensions = get_loaded_extensions();

return in_array('libxml', $extensions, true) && in_array('dom', $extensions, true);
return \in_array('libxml', $extensions, true) && \in_array('dom', $extensions, true);
}

public function setLoadFromNet(bool $loadFromNet)
Expand Down
4 changes: 2 additions & 2 deletions src/Parser/Php/Configurator/TraverserConfigurator.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function configure(NodeTraverserInterface $traverser)
$visitorIds = array_values(array_intersect($registeredVisitorsIds, $configuredVisitorIds));
$unknownConfiguredVisitorIds = array_diff($configuredVisitorIds, $registeredVisitorsIds);

if (count($unknownConfiguredVisitorIds)) {
if (\count($unknownConfiguredVisitorIds)) {
throw new RuntimeException(
sprintf('Found unknown php_parser visitors: %s', implode(',', $unknownConfiguredVisitorIds))
);
Expand All @@ -113,7 +113,7 @@ public function configure(NodeTraverserInterface $traverser)
}

$options = $configuredVisitors[$visitorAlias];
if ($visitor instanceof ConfigurableVisitorInterface && is_array($options)) {
if ($visitor instanceof ConfigurableVisitorInterface && \is_array($options)) {
$visitor->configure($options);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function leaveNode(Node $node)
$variable = $node->var->name;
$method = $node->name;
$normalized = sprintf('$%s->%s', $variable, $method);
if (!in_array($normalized, $this->blacklist, true)) {
if (!\in_array($normalized, $this->blacklist, true)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Parser/Php/Visitor/ForbiddenFunctionCallsVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function leaveNode(Node $node)
}

$function = $node->name;
if (!in_array($function, $this->blacklist, false)) {
if (!\in_array($function, $this->blacklist, false)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function leaveNode(Node $node)
$method = $node->name;
$normalized = sprintf('%s::%s', $class, $method);

if (!in_array($normalized, $this->blacklist, true)) {
if (!\in_array($normalized, $this->blacklist, true)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Process/AsyncProcessRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private function watchProcesses(): bool
}
}

return 0 !== count($this->processes);
return 0 !== \count($this->processes);
}

private function handleProcess(Process $process): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Process/ProcessBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private function guardWindowsCmdMaxInputStringLimitation(Process $process)
return;
}

if (strlen($process->getCommandLine()) <= Platform::WINDOWS_COMMANDLINE_STRING_LIMITATION) {
if (\strlen($process->getCommandLine()) <= Platform::WINDOWS_COMMANDLINE_STRING_LIMITATION) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Runner/TaskRunnerContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function skipSuccessOutput(): bool

public function setSkipSuccessOutput(bool $skipSuccessOutput)
{
$this->skipSuccessOutput = (bool) $skipSuccessOutput;
$this->skipSuccessOutput = $skipSuccessOutput;
}

public function hasTestSuite(): bool
Expand Down
2 changes: 1 addition & 1 deletion src/Task/Ant.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function run(ContextInterface $context): TaskResultInterface
{
$config = $this->getConfiguration();
$files = $context->getFiles()->extensions($config['triggered_by']);
if (0 === count($files)) {
if (0 === \count($files)) {
return TaskResult::createSkipped($this, $context);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Task/Atoum.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function canRunInContext(ContextInterface $context): bool
public function run(ContextInterface $context): TaskResultInterface
{
$files = $context->getFiles()->name('*.php');
if (0 === count($files)) {
if (0 === \count($files)) {
return TaskResult::createSkipped($this, $context);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Task/Behat.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function canRunInContext(ContextInterface $context): bool
public function run(ContextInterface $context): TaskResultInterface
{
$files = $context->getFiles()->name('*.php');
if (0 === count($files)) {
if (0 === \count($files)) {
return TaskResult::createSkipped($this, $context);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Task/Brunch.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function run(ContextInterface $context): TaskResultInterface
{
$config = $this->getConfiguration();
$files = $context->getFiles()->extensions($config['triggered_by']);
if (0 === count($files)) {
if (0 === \count($files)) {
return TaskResult::createSkipped($this, $context);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Task/Codeception.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function canRunInContext(ContextInterface $context): bool
public function run(ContextInterface $context): TaskResultInterface
{
$files = $context->getFiles()->name('*.php');
if (0 === count($files)) {
if (0 === \count($files)) {
return TaskResult::createSkipped($this, $context);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Task/Composer.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public function run(ContextInterface $context): TaskResultInterface
$files = $context->getFiles()
->path(pathinfo($config['file'], PATHINFO_DIRNAME))
->name(pathinfo($config['file'], PATHINFO_BASENAME));
if (0 === count($files)) {
if (0 === \count($files)) {
return TaskResult::createSkipped($this, $context);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Task/ComposerRequireChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public function run(ContextInterface $context): TaskResultInterface
$config = $this->getConfiguration();
$files = $context->getFiles()->names($config['triggered_by']);

if (0 === count($files)) {
if (0 === \count($files)) {
return TaskResult::createSkipped($this, $context);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Task/ComposerScript.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function run(ContextInterface $context): TaskResultInterface
{
$config = $this->getConfiguration();
$files = $context->getFiles()->extensions($config['triggered_by']);
if (0 === count($files)) {
if (0 === \count($files)) {
return TaskResult::createSkipped($this, $context);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Task/Deptrac.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function run(ContextInterface $context): TaskResultInterface
$config = $this->getConfiguration();

$files = $context->getFiles()->name('*.php');
if (0 === count($files)) {
if (0 === \count($files)) {
return TaskResult::createSkipped($this, $context);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Task/DoctrineOrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function run(ContextInterface $context): TaskResultInterface
$config = $this->getConfiguration();
$files = $context->getFiles()->extensions($config['triggered_by']);

if (0 === count($files)) {
if (0 === \count($files)) {
return TaskResult::createSkipped($this, $context);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Task/Gherkin.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function run(ContextInterface $context): TaskResultInterface
{
$config = $this->getConfiguration();
$files = $context->getFiles()->extensions(['feature']);
if (0 === count($files)) {
if (0 === \count($files)) {
return TaskResult::createSkipped($this, $context);
}

Expand Down
Loading

0 comments on commit 1952e7e

Please sign in to comment.