symfony/symfony — pull request #9721 by djlambert (2013-12-06 23:51:50+00:00)
Title: [Security] [Acl] [AclVoter] Refactor and reduce complexity

| Q | A
| ------------- | ---
| Bug fix? | no
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| Fixed tickets |
| License | MIT
| Doc PR |

While working through understanding the internals of the Security component and extending some of the classes for my own implementation it seemed there was room to optimize the existing code. I started with the AclVoter class. If these changes are useful I can tackle additional classes.

The one thing that jumped out at me was the amount of code in the main ```foreach``` loop of the ```vote()``` method used to setup variables whose value would not change within the block. Additionally there were reoccurring statement blocks adding noise to the actual logic of the method. After refactoring and moving code out of the ```foreach``` loop PHPMD reports a reduction of cyclomatic complexity from 25 to 14 and NPath complexity from 73729 to 360.

I modified the few tests which were expecting calls to the ```PermissionMap``` object and added an additional test for the case of the voter abstaining when no attributes match in the ```PermissionMap```.