-
-
Notifications
You must be signed in to change notification settings - Fork 74
Create namespace for whitelisted classes #138
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
Merged
theofidry
merged 25 commits into
humbug:master
from
moorscode:135-create-namespace-for-whitelisted-class
Jan 8, 2018
Merged
Changes from all commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
246054a
Create namespace for whitelisted classes
moorscode 528472f
Tab -> spaces
moorscode fc0e756
Apply PSR-2
moorscode b0a919d
PSR-2
moorscode 2f79890
Fix code style problems
moorscode 05fb35d
Fix styling problems
moorscode 620c4ed
Namespace anything around a whitelisted class
moorscode fc75eb5
Refactor and split up code
moorscode f1da747
Apply CR
moorscode 00a19ce
Remove unintended spec
moorscode 0695fcb
Apply CS
moorscode 9240fa8
Added more interface specs
moorscode 2cfedb0
Follow scrutinizer suggestion
moorscode 84c34ab
Node has parent always means don't wrap.
moorscode f4f77e1
Added tests for traits and anonymous classes
moorscode 4fc6221
Added test for abstract class
moorscode bafa89f
Add final class spec
moorscode fae405a
Remove unused argument
moorscode 1eb03b2
Check for empty array instead of general empty
moorscode 2615e96
Remove self-explanatory documentation
moorscode 6c26bb7
Add simple description of parameter
moorscode 2fd6d5d
Move logic into Namespace Statement Prefixer
moorscode afd7ecc
Fix code style
moorscode e4e0849
Reduce complexity
moorscode 43815c1
Apply CR
moorscode File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,300 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /* | ||
| * This file is part of the humbug/php-scoper package. | ||
| * | ||
| * Copyright (c) 2017 Théo FIDRY <[email protected]>, | ||
| * Pádraic Brady <[email protected]> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| return [ | ||
| 'meta' => [ | ||
| 'title' => 'Namespace declaration creation for whitelisted classes which belong to the global namespace.', | ||
| // Default values. If not specified will be the one used | ||
| 'prefix' => 'Humbug', | ||
| 'whitelist' => [], | ||
| ], | ||
|
|
||
| 'Single class should receive namespace' => <<<'PHP' | ||
| <?php | ||
|
|
||
| class AppKernel | ||
| { | ||
| } | ||
|
|
||
| ---- | ||
| <?php | ||
|
|
||
| namespace Humbug; | ||
|
|
||
| class AppKernel | ||
| { | ||
| } | ||
|
|
||
| PHP | ||
| , | ||
|
|
||
| 'Single abstract class should receive namespace.' => <<<'PHP' | ||
| <?php | ||
|
|
||
| abstract class AppKernel | ||
| { | ||
| } | ||
|
|
||
| ---- | ||
| <?php | ||
|
|
||
| namespace Humbug; | ||
|
|
||
| abstract class AppKernel | ||
| { | ||
| } | ||
|
|
||
| PHP | ||
| , | ||
|
|
||
| 'Final class declaration should be prefixed.' => <<<'PHP' | ||
| <?php | ||
|
|
||
| final class AppKernel {} | ||
| ---- | ||
| <?php | ||
|
|
||
| namespace Humbug; | ||
|
|
||
| final class AppKernel | ||
| { | ||
| } | ||
|
|
||
| PHP | ||
| , | ||
|
|
||
| 'Interfaces can be whitelisted too.' => <<<'PHP' | ||
| <?php | ||
|
|
||
| interface AppKernel | ||
| { | ||
| } | ||
|
|
||
| ---- | ||
| <?php | ||
|
|
||
| namespace Humbug; | ||
|
|
||
| interface AppKernel | ||
| { | ||
| } | ||
|
|
||
| PHP | ||
| , | ||
|
|
||
| 'Multiple classes should all receive namespace in the same file.' => <<<'PHP' | ||
| <?php | ||
|
|
||
| class AppKernalOther2 | ||
| { | ||
| } | ||
|
|
||
| class AppKernel | ||
| { | ||
| } | ||
|
|
||
| class AppKernalOther | ||
| { | ||
| } | ||
|
|
||
| ---- | ||
| <?php | ||
|
|
||
| namespace { | ||
| class AppKernalOther2 | ||
| { | ||
| } | ||
| } | ||
| namespace Humbug { | ||
| class AppKernel | ||
| { | ||
| } | ||
| } | ||
| namespace { | ||
| class AppKernalOther | ||
| { | ||
| } | ||
| } | ||
|
|
||
| PHP | ||
| , | ||
|
|
||
| 'Multiple interfaces should all receive namespace in the same file.' => <<<'PHP' | ||
| <?php | ||
|
|
||
| interface AppKernel | ||
| { | ||
| } | ||
|
|
||
| class AppKernalOther | ||
| { | ||
| } | ||
|
|
||
| interface SomeInterface | ||
| { | ||
| } | ||
|
|
||
| ---- | ||
| <?php | ||
|
|
||
| namespace Humbug { | ||
| interface AppKernel | ||
| { | ||
| } | ||
| } | ||
| namespace { | ||
| class AppKernalOther | ||
| { | ||
| } | ||
| } | ||
| namespace { | ||
| interface SomeInterface | ||
| { | ||
| } | ||
| } | ||
|
|
||
| PHP | ||
| , | ||
|
|
||
| 'Defines should be wrapped in namespace alongside whitelisted class.' => <<<'PHP' | ||
| <?php | ||
|
|
||
| define("MY_DEFINE", "value"); | ||
|
|
||
| class AppKernel | ||
| { | ||
| } | ||
|
|
||
| ---- | ||
| <?php | ||
|
|
||
| namespace { | ||
| \define("MY_DEFINE", "value"); | ||
| } | ||
| namespace Humbug { | ||
| class AppKernel | ||
| { | ||
| } | ||
| } | ||
|
|
||
| PHP | ||
| , | ||
|
|
||
| 'Make sure anonymous classes are not wrapped.' => <<<'PHP' | ||
| <?php | ||
|
|
||
| new class {}; | ||
|
|
||
| class AppKernel | ||
| { | ||
| } | ||
|
|
||
| ---- | ||
| <?php | ||
|
|
||
| namespace { | ||
| new class | ||
| { | ||
| }; | ||
| } | ||
| namespace Humbug { | ||
| class AppKernel | ||
| { | ||
| } | ||
| } | ||
|
|
||
| PHP | ||
| , | ||
|
|
||
| 'Make sure traits are not prefixed.' => <<<'PHP' | ||
| <?php | ||
|
|
||
| trait AppKernel | ||
| { | ||
| } | ||
|
|
||
| ---- | ||
| <?php | ||
|
|
||
| trait AppKernel | ||
| { | ||
| } | ||
|
|
||
| PHP | ||
| , | ||
|
|
||
| 'Make sure traits are not prefixed next to whitelisted class.' => <<<'PHP' | ||
| <?php | ||
|
|
||
| trait SomeTrait | ||
| { | ||
| } | ||
|
|
||
| class AppKernel | ||
| { | ||
| } | ||
|
|
||
| ---- | ||
| <?php | ||
|
|
||
| namespace { | ||
| trait SomeTrait | ||
| { | ||
| } | ||
| } | ||
| namespace Humbug { | ||
| class AppKernel | ||
| { | ||
| } | ||
| } | ||
|
|
||
| PHP | ||
| , | ||
|
|
||
| 'Traits in different namespace.' => <<<'PHP' | ||
| <?php | ||
|
|
||
| namespace Foo { | ||
| trait SomeTrait{} | ||
| } | ||
|
|
||
| namespace { | ||
| class AppKernel{} | ||
| } | ||
|
|
||
| namespace { | ||
| class Bla{} | ||
| } | ||
|
|
||
| ---- | ||
| <?php | ||
|
|
||
| namespace Humbug\Foo { | ||
| trait SomeTrait | ||
| { | ||
| } | ||
| } | ||
| namespace Humbug { | ||
| class AppKernel | ||
| { | ||
| } | ||
| } | ||
| namespace { | ||
| class Bla | ||
| { | ||
| } | ||
| } | ||
|
|
||
| PHP | ||
| ]; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is also a few other cases that you can find in
specs/classthat needs to be accounted for. For example it should also apply to:traits: they cannot be whitelisted; may require a test that it doesn't work there stillanonymous: they cannot be whitelisted; may require a test that it doesn't work there still