Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Priority?) Issue with semicolon_after_instruction and space_after_semicolon #3856

Closed
dmvdbrugge opened this issue Jul 3, 2018 · 2 comments
Labels

Comments

@dmvdbrugge
Copy link
Contributor

See code below, there are 2 <?php endif;?> occurrences that need to be fixed. If I run only space_after_semicolon, they both get fixed. If I run the full set, only 1 of them gets fixed the first run, a second run fixes the other as well. Because of the 1 fix 1 not fix I thought it might be more than "just" a priority issue, but let's hope not.

For the same reason I included a rather big example (nested stuff), it might be reproducable with way less.

The PHP version you are using ($ php -v):

PHP 7.1.18 (cli) (built: May 25 2018 19:18:59) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.1.18, Copyright (c) 1999-2018, by Zend Technologies

PHP CS Fixer version you are using ($ php-cs-fixer -V):

PHP CS Fixer 2.12.1 Long Journey by Fabien Potencier and Dariusz Ruminski

The command you use to run PHP CS Fixer:

  • Full set
vendor/bin/php-cs-fixer fix -v --using-cache=no
  • Only conflicting fixers
vendor/bin/php-cs-fixer fix --using-cache=no --verbose --diff --rules='{"space_after_semicolon":{"remove_in_empty_for_expressions":true},"semicolon_after_instruction":true}'

The configuration file you are using, if any:

Basically the same as dmvdbrugge/dynamic-components, except explicit_string_variable, header_comment, no_alternative_syntax, and no_unset_on_property

If applicable, please provide minimum samples of PHP code (as plain text, not screenshots):

  • before running PHP CS Fixer (no changes):
if (isset($status_overview)):

    ?>
    <<?php echo $header_tag; ?>>Status Overview</<?php echo $header_tag; ?>>

    <table class="listing yellow auto_zebra_stripes" summary="Status Overview">
        <thead>
        <tr>
            <th>&nbsp;</th>
            <th>Service</th>
            <th>Description</th>
            <th width="40%">Status</th>
            <th>Action</th>
        </tr>
        </thead>

        <tbody>
        <?php if ($status_overview):?>
            <?php
            $icon_mapping = array(
                Service::STATUS_OK   => '/icons/bullet_green.png',
                Service::STATUS_WARN => '/icons/bullet_warning.gif',
                Service::STATUS_ERR  => '/icons/bullet_error.gif'
            );

            foreach ($status_overview as $i => $service_status):

                // Skip OK services
                if (!isset($show_all_services) and $service_status['status'] === Service::STATUS_OK) {
                    continue;
                }

                $class_name = '';
                $status_icon = $icon_mapping[$service_status['status']];

                if ($service_status['status'] != Service::STATUS_OK) {
                    $class_name = 'problem';
                }?>

                <tr class="<?php echo $class_name?>">
                    <td><img src="<?php echo $status_icon?>" /></td>
                    <td><?php echo h($service_status['name'])?></td>
                    <td><?php echo h($service_status['description'])?></td>
                    <td><?php echo h($service_status['status_message'] ? $service_status['status_message'] : '-')?></td>

                    <td class="link">
                        <?php if ($service_status['status_action']):?>
                            <a href="<?php echo $service_status['status_action']?>">act</a>
                        <?php endif;?>

                    </td>
                </tr>
            <?php endforeach; ?>
        <?php else:?>
            <tr>
                <td colspan="5"><em>No services to list</em></td>
            </tr>
        <?php endif;?>
        </tbody>
    </table>
<?php

    endif;
  • after first run:
--- Original
+++ New
@@ @@
             <?php
-            $icon_mapping = array(
+            $icon_mapping = [
                 Service::STATUS_OK   => '/icons/bullet_green.png',
                 Service::STATUS_WARN => '/icons/bullet_warning.gif',
-                Service::STATUS_ERR  => '/icons/bullet_error.gif'
-            );
+                Service::STATUS_ERR  => '/icons/bullet_error.gif',
+            ];
@@ @@

-                $class_name = '';
+                $class_name  = '';
@@ @@

-                <tr class="<?php echo $class_name?>">
-                    <td><img src="<?php echo $status_icon?>" /></td>
-                    <td><?php echo h($service_status['name'])?></td>
-                    <td><?php echo h($service_status['description'])?></td>
-                    <td><?php echo h($service_status['status_message'] ? $service_status['status_message'] : '-')?></td>
+                <tr class="<?php echo $class_name; ?>">
+                    <td><img src="<?php echo $status_icon; ?>" /></td>
+                    <td><?php echo h($service_status['name']); ?></td>
+                    <td><?php echo h($service_status['description']); ?></td>
+                    <td><?php echo h($service_status['status_message'] ? $service_status['status_message'] : '-'); ?></td>

                     <td class="link">
                         <?php if ($service_status['status_action']):?>
-                            <a href="<?php echo $service_status['status_action']?>">act</a>
-                        <?php endif;?>
+                            <a href="<?php echo $service_status['status_action']; ?>">act</a>
+                        <?php endif; ?>

                     </td>
                 </tr>
             <?php endforeach; ?>
         <?php else:?>
             <tr>
                 <td colspan="5"><em>No services to list</em></td>
             </tr>
         <?php endif;?>
         </tbody>
     </table>
 <?php

     endif;
  • after second run:
--- Original
+++ New
@@ @@
             </tr>
-        <?php endif;?>
+        <?php endif; ?>
         </tbody>
     </table>
 <?php

     endif;
  • expected:
    Immediately arrive at the last step

Meta: this is case 10 of #3844

@dmvdbrugge
Copy link
Contributor Author

Forgot to note, but as can be seen at case 10 of #3844, space_after_semicolon has been applied after semicolon_after_instruction, which is another reason I don't think it actually is a priority issue.

@dmvdbrugge dmvdbrugge changed the title (Priority?) Issue with semicolon_after_instruction and space_after_semicolon (Priority?) Issue with semicolon_after_instruction and space_after_semicolon Jul 3, 2018
@SpacePossum
Copy link
Contributor

Reducing the sample a bit :)

<?php if ($a):?>
1
<?php endif;?>
<?php if ($b):?>
2
<?php endif;?>
<?php if ($c):?>
3
<?php endif;?>
4

with space_after_semicolon, after first run;

<?php if ($a):?>
1
<?php endif; ?>
<?php if ($b):?>
2
<?php endif; ?>
<?php if ($c):?>
3
<?php endif;?>
4

this shows the last endif; is not fixed, it gets fixed on the second run

SpacePossum added a commit that referenced this issue Jul 4, 2018
This PR was squashed before being merged into the 2.12 branch (closes #3866).

Discussion
----------

SpaceAfterSemicolonFixer - loop over all tokens

closes #3856

Commits
-------

9675267 SpaceAfterSemicolonFixer - loop over all tokens
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants