Skip to content

Conversation

@peter279k
Copy link
Collaborator

Applying the CountOnNullRector rule via the rector.

 6/6 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100%
6 files with changes
====================

1) src/ExceptionPrinter/DevelopmentExceptionPrinter.php:125

    ---------- begin diff ----------
@@ @@
         $this->logger->info("Thrown from $file at line $line:\n");

         $lines = file($file);
-        $indexRange = range(max($line - 4, 0), min($line + 3, count($lines)));
+        $indexRange = range(max($line - 4, 0), min($line + 3, is_array($lines) || $lines instanceof \Countable ? count($lines) : 0));
         foreach($indexRange as $index) {
             if ($index == ($line - 1)) {
                 $this->logger->warn(sprintf("> % 3d", $index + 1) . rtrim($lines[$index]));
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


2) src/Debug/LineIndicator.php:22

    ---------- begin diff ----------
@@ @@
     {
         $lines = file($file);
         $fromIndex = max($line - 1 - $this->contextLines, 0);
-        $toIndex = min($line - 1 + $this->contextLines, count($lines));
+        $toIndex = min($line - 1 + $this->contextLines, is_array($lines) || $lines instanceof \Countable ? count($lines) : 0);

         if ($fromIndex === $toIndex) {
             $indexRange = [ $fromIndex ];
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


3) src/Component/Table/Table.php:164

    ---------- begin diff ----------
@@ @@

             $lines = $attribute->handleTextOverflow($cell, $this->maxColumnWidth);

-            if (count($lines) == 1) {
+            if ((is_array($lines) || $lines instanceof \Countable ? count($lines) : 0) == 1) {
                 $lines[0] = $attribute->format($lines[0]);
             }
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


4) src/Completion/BashGenerator.php:377

    ---------- begin diff ----------
@@ @@
         // local argument_min_length=0
         $argInfos = $cmd->getArgInfoList();
         // $buf->appendLine("local argument_min_length=" . count($argInfos));
-        $buf->appendLine(local_bash_var('argument_min_length', count($argInfos)));
+        $buf->appendLine(local_bash_var('argument_min_length', is_array($argInfos) || $argInfos instanceof \Countable ? count($argInfos) : 0));


         $buf->append('
@@ @@
         $buf->appendLine('      fi');
         $buf->appendLine('      # If the command requires at least $argument_min_length to run, we check the argument');

-        if (count($argInfos) > 0) {
+        if ((is_array($argInfos) || $argInfos instanceof \Countable ? count($argInfos) : 0) > 0) {
             $buf->appendLine('if [[ $argument_min_length > 0 ]] ; then');

             // $buf->appendLine('echo argument_index: [$argument_index]');
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


5) src/CommandBase.php:795

    ---------- begin diff ----------
@@ @@
         // Validating arguments
         $argInfos = $this->getArgInfoList();

-        for ($i = 0; $i < count($argInfos); $i++ ) {
+        for ($i = 0; $i < (is_array($argInfos) || $argInfos instanceof \Countable ? count($argInfos) : 0); $i++ ) {
             $argInfo = $argInfos[$i];
             if (isset($args[$i])) {
                 $arg = $args[$i];
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)


6) src/Command/HelpCommand.php:198

    ---------- begin diff ----------
@@ @@
             $ret = $app->aggregate();

             // show "General commands" title if there are more than one groups
-            if (count($ret['groups']) > 1 || $this->options->dev) {
+            if ((is_array($ret['groups']) || $ret['groups'] instanceof \Countable ? count($ret['groups']) : 0) > 1 || $this->options->dev) {
                 $this->logger->writeln('  '.$formatter->format('General Commands', 'strong_white'));
             }
             $this->layoutCommands($ret['commands']);
    ----------- end diff -----------

Applied rules:
 * CountOnNullRector (https://3v4l.org/Bndc9)

@peter279k peter279k self-assigned this Apr 20, 2023
@peter279k peter279k requested a review from c9s April 20, 2023 07:23
@peter279k peter279k merged commit 01781f0 into c9s:3.0 Apr 20, 2023
@peter279k peter279k deleted the count_on_null_rector branch April 20, 2023 08:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants