├── .github
└── workflows
│ └── test.yml
├── .gitignore
├── .sensiolabs.yml
├── LICENSE
├── README.md
├── bin
└── deprecation-detector
├── box.json
├── composer.json
├── composer.lock
├── examples
├── Arguments.php
├── BreakingClass.php
├── Controller.php
├── FormType.php
├── HelloWorld.php
├── LanguageDeprecations.php
├── deprecations.php
└── dynamic
│ ├── CallConstructorFirst.php
│ ├── TrackingArguments.php
│ └── TrackingVariables.php
├── phpunit.xml.dist
├── src
├── Configuration
│ └── Configuration.php
├── Console
│ ├── Application.php
│ ├── Command
│ │ └── CheckCommand.php
│ └── Output
│ │ ├── DefaultProgressOutput.php
│ │ └── VerboseProgressOutput.php
├── DeprecationDetector.php
├── DetectorFactory.php
├── FileInfo
│ ├── Deprecation
│ │ ├── ClassDeprecation.php
│ │ ├── DeprecationInterface.php
│ │ ├── FunctionDeprecation.php
│ │ ├── InterfaceDeprecation.php
│ │ └── MethodDeprecation.php
│ ├── DeprecationCollectionInterface.php
│ ├── MethodDefinition.php
│ ├── PhpFileInfo.php
│ └── Usage
│ │ ├── ClassUsage.php
│ │ ├── DeprecatedLanguageUsage.php
│ │ ├── FunctionUsage.php
│ │ ├── InterfaceUsage.php
│ │ ├── MethodUsage.php
│ │ ├── SuperTypeUsage.php
│ │ ├── TypeHintUsage.php
│ │ └── UsageInterface.php
├── Finder
│ ├── DeprecationFinderFactory.php
│ ├── FinderFactoryInterface.php
│ ├── ParsedPhpFileFinder.php
│ ├── Result.php
│ └── UsageFinderFactory.php
├── Parser
│ ├── DeprecationParser.php
│ ├── ParserInterface.php
│ └── UsageParser.php
├── Resources
│ └── templates
│ │ └── htmlTable.phtml
├── RuleSet
│ ├── Cache.php
│ ├── DirectoryTraverser.php
│ ├── Loader
│ │ ├── Composer
│ │ │ ├── Composer.php
│ │ │ ├── ComposerFactory.php
│ │ │ ├── ComposerLoader.php
│ │ │ ├── Exception
│ │ │ │ ├── ComposerException.php
│ │ │ │ ├── ComposerFileDoesNotExistsException.php
│ │ │ │ └── ComposerFileIsInvalidException.php
│ │ │ └── Package.php
│ │ ├── CouldNotLoadRuleSetException.php
│ │ ├── DirectoryLoader.php
│ │ ├── FileLoader.php
│ │ └── LoaderInterface.php
│ └── RuleSet.php
├── TypeGuessing
│ ├── AncestorResolver.php
│ ├── ConstructorResolver
│ │ ├── ConstructorResolver.php
│ │ └── Visitor
│ │ │ └── ConstructorResolverVisitor.php
│ ├── SymbolTable
│ │ ├── ComposedResolver.php
│ │ ├── Resolver
│ │ │ ├── ArgumentResolver.php
│ │ │ ├── PropertyAssignResolver.php
│ │ │ ├── ReattachStateToProperty.php
│ │ │ ├── ReattachStateToVariable.php
│ │ │ ├── ResolverInterface.php
│ │ │ ├── SymfonyResolver.php
│ │ │ └── VariableAssignResolver.php
│ │ ├── Symbol.php
│ │ ├── SymbolTable.php
│ │ ├── TableScope.php
│ │ └── Visitor
│ │ │ └── SymbolTableVariableResolverVisitor.php
│ └── Symfony
│ │ └── ContainerReader.php
├── Violation
│ ├── Renderer
│ │ ├── Console
│ │ │ ├── BaseRenderer.php
│ │ │ ├── DefaultRenderer.php
│ │ │ └── SimpleRenderer.php
│ │ ├── Html
│ │ │ ├── Renderer.php
│ │ │ └── RendererFactory.php
│ │ ├── MessageHelper
│ │ │ ├── Message
│ │ │ │ ├── BaseViolationMessage.php
│ │ │ │ ├── ClassViolationMessage.php
│ │ │ │ ├── FunctionViolationMessage.php
│ │ │ │ ├── InterfaceViolationMessage.php
│ │ │ │ ├── LanguageDeprecationMessage.php
│ │ │ │ ├── MethodDefinitionViolationMessage.php
│ │ │ │ ├── MethodViolationMessage.php
│ │ │ │ ├── SuperTypeViolationMessage.php
│ │ │ │ └── ViolationMessageInterface.php
│ │ │ └── MessageHelper.php
│ │ └── RendererInterface.php
│ ├── Violation.php
│ ├── ViolationChecker
│ │ ├── ClassViolationChecker.php
│ │ ├── ComposedViolationChecker.php
│ │ ├── FunctionViolationChecker.php
│ │ ├── InterfaceViolationChecker.php
│ │ ├── LanguageViolationChecker.php
│ │ ├── MethodDefinitionViolationChecker.php
│ │ ├── MethodViolationChecker.php
│ │ ├── SuperTypeViolationChecker.php
│ │ ├── TypeHintViolationChecker.php
│ │ └── ViolationCheckerInterface.php
│ ├── ViolationDetector.php
│ └── ViolationFilter
│ │ ├── ComposedViolationFilter.php
│ │ ├── MethodViolationFilter.php
│ │ └── ViolationFilterInterface.php
└── Visitor
│ ├── Deprecation
│ └── FindDeprecatedTagsVisitor.php
│ ├── DeprecationVisitorInterface.php
│ ├── StaticAnalysisVisitorInterface.php
│ ├── Usage
│ ├── FindArguments.php
│ ├── FindClasses.php
│ ├── FindFunctionCalls.php
│ ├── FindInterfaces.php
│ ├── FindLanguageDeprecations.php
│ ├── FindMethodCalls.php
│ ├── FindMethodDefinitions.php
│ ├── FindStaticMethodCalls.php
│ └── FindSuperTypes.php
│ ├── ViolationVisitorInterface.php
│ └── VisitorInterface.php
└── tests
├── Configuration
└── ConfigurationTest.php
├── Console
├── Command
│ └── CheckCommandTest.php
└── Output
│ ├── DefaultProgressOutputTest.php
│ └── VerboseProgressOutputTest.php
├── DeprecationDetectorTest.php
├── DetectorFactoryTest.php
├── FileInfo
├── Deprecation
│ ├── ClassDeprecationTest.php
│ ├── FunctionDeprecationTest.php
│ ├── InterfaceDeprecationTest.php
│ └── MethodDeprecationTest.php
├── MethodDefinitionTest.php
├── PhpFileInfoTest.php
└── Usage
│ ├── ClassUsageTest.php
│ ├── DeprecatedLanguageUsageTest.php
│ ├── FunctionUsageTest.php
│ ├── InterfaceUsageTest.php
│ ├── MethodUsageTest.php
│ ├── SuperTypeUsageTest.php
│ └── TypeHintUsageTest.php
├── Finder
├── DeprecationFinderFactoryTest.php
├── ParsedPhpFileFinderTest.php
├── ResultTest.php
└── UsageFinderFactoryTest.php
├── Parser
├── DeprecationParserTest.php
└── UsageParserTest.php
├── RuleSet
├── CacheTest.php
├── DirectoryTraverserTest.php
├── Loader
│ ├── Composer
│ │ ├── ComposerFactoryTest.php
│ │ ├── ComposerLoaderTest.php
│ │ ├── ComposerTest.php
│ │ ├── Exception
│ │ │ ├── ComposerExceptionTest.php
│ │ │ ├── ComposerFileDoesNotExistsExceptionTest.php
│ │ │ └── ComposerFileIsInvalidExceptionTest.php
│ │ └── PackageTest.php
│ ├── CouldNotLoadRuleSetExceptionTest.php
│ └── FileLoaderTest.php
└── RuleSetTest.php
├── TypeGuessing
├── ConstructorResolver
│ ├── ConstructorResolverTest.php
│ └── Visitor
│ │ └── ConstructorResolverVisitorTest.php
├── SymbolTable
│ ├── ComposedResolverTest.php
│ ├── Resolver
│ │ ├── ArgumentResolverTest.php
│ │ ├── PropertyAssignResolverTest.php
│ │ ├── ReattachStateToPropertyTest.php
│ │ ├── ReattachStateToVariableTest.php
│ │ ├── SymfonyResolverTest.php
│ │ └── VariableAssignResolverTest.php
│ ├── SymbolTableTest.php
│ ├── SymbolTest.php
│ ├── TableScopeTest.php
│ └── Visitor
│ │ └── SymbolTableVariableResolverVisitorTest.php
└── Symfony
│ ├── ContainerReaderTest.php
│ └── containerDump.xml
├── Violation
├── Renderer
│ ├── Html
│ │ ├── RendererFactoryTest.php
│ │ └── RendererTest.php
│ └── MessageHelper
│ │ ├── Message
│ │ ├── BaseViolationMessageImplementation.php
│ │ ├── BaseViolationMessageTest.php
│ │ ├── ClassViolationMessageTest.php
│ │ ├── FunctionViolationMessageTest.php
│ │ ├── InterfaceViolationMessageTest.php
│ │ ├── LanguageDeprecationMessageTest.php
│ │ ├── MethodDefinitionViolationMessageTest.php
│ │ ├── MethodViolationMessageTest.php
│ │ └── SuperTypeViolationMessageTest.php
│ │ └── MessageHelperTest.php
├── ViolationChecker
│ ├── ClassViolationCheckerTest.php
│ ├── ComposedViolationCheckerTest.php
│ ├── InterfaceViolationCheckerTest.php
│ ├── MethodViolationCheckerTest.php
│ ├── SuperTypeViolationCheckerTest.php
│ └── TypeHintViolationCheckerTest.php
├── ViolationDetectorTest.php
├── ViolationFilter
│ ├── ComposedViolationFilterTest.php
│ └── MethodViolationFilterTest.php
└── ViolationTest.php
└── Visitor
└── Usage
├── FindArgumentsTest.php
├── FindClassesTest.php
├── FindInterfacesTest.php
├── FindLanguageDeprecationsTest.php
├── FindStaticMethodCallsTest.php
├── FindSuperTypesTest.php
└── FindTestCase.php
/.github/workflows/test.yml:
--------------------------------------------------------------------------------
1 | name: "Tests"
2 |
3 | on:
4 | pull_request:
5 | branches: [ master ]
6 | push:
7 | branches: [master]
8 | tags: ["**"]
9 |
10 | jobs:
11 | unit-tests:
12 | name: "Unit Tests for PHP ${{ matrix.php-version }}"
13 | runs-on: ubuntu-latest
14 | strategy:
15 | matrix:
16 | php-version: ['5.6', '7.0', '7.1', '7.2', '7.3', '7.4']
17 | steps:
18 | - name: "Checkout"
19 | uses: actions/checkout@v2
20 |
21 | - name: "Set up PHP ${{ matrix.php-version }}"
22 | uses: shivammathur/setup-php@v2
23 | with:
24 | php-version: "${{ matrix.php-version }}"
25 | extensions: mbstring, xml, ctype, iconv
26 | coverage: none
27 | tools: "composer:v2"
28 |
29 | - name: Get composer cache directory
30 | id: composercache
31 | run: echo "::set-output name=dir::$(composer config cache-files-dir)"
32 |
33 | - name: Cache composer dependencies
34 | uses: actions/cache@v2
35 | with:
36 | path: ${{ steps.composercache.outputs.dir }}
37 | key: composer-${{ runner.os }}-${{ matrix.php-version }}-${{ hashFiles('composer.*') }}
38 | restore-keys: |
39 | composer-${{ runner.os }}-${{ matrix.php-version }}-
40 | composer-${{ runner.os }}-
41 | composer-
42 |
43 | - name: "Install dependencies"
44 | run: composer install
45 |
46 | - name: "Run tests"
47 | run: php vendor/bin/phpunit
48 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | vendor
2 | phpunit.xml
3 | .rules/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (c) 2014-2015 SensioLabs Deutschland GmbH
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining a copy
4 | of this software and associated documentation files (the "Software"), to deal
5 | in the Software without restriction, including without limitation the rights
6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7 | copies of the Software, and to permit persons to whom the Software is furnished
8 | to do so, subject to the following conditions:
9 |
10 | The above copyright notice and this permission notice shall be included in all
11 | copies or substantial portions of the Software.
12 |
13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19 | THE SOFTWARE.
--------------------------------------------------------------------------------
/bin/deprecation-detector:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env php
2 | run();
19 |
--------------------------------------------------------------------------------
/box.json:
--------------------------------------------------------------------------------
1 | {
2 | "output": "deprecation-detector.phar",
3 | "chmod": "0755",
4 | "compactors": [
5 | "Herrera\\Box\\Compactor\\Php"
6 | ],
7 | "extract": false,
8 | "main": "bin/deprecation-detector",
9 | "finder": [
10 | {
11 | "name": "*.*",
12 | "exclude": ["Tests"],
13 | "in": "vendor"
14 | },
15 | {
16 | "name": "*.*",
17 | "in": "src"
18 | }
19 | ],
20 | "stub": true,
21 | "web": false
22 | }
23 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "sensiolabs-de/deprecation-detector",
3 | "type": "application",
4 | "description": "Command line tool to detect usage of deprecated code",
5 | "license": "MIT",
6 | "authors": [
7 | {
8 | "name": "Marvin Klemp",
9 | "email": "marvin.klemp@sensiolabs.de"
10 | },
11 | {
12 | "name": "The SensioLabs Deutschland Team",
13 | "email": "opensource@sensiolabs.de"
14 | }
15 | ],
16 | "require": {
17 | "php": ">=5.5.9 || ^7.0",
18 | "nikic/php-parser": "~3.0",
19 | "symfony/console": "^2.6 || ^3.0",
20 | "symfony/finder": "^2.6 || ^3.0",
21 | "phpdocumentor/reflection-docblock": "~2.0 || ~3.0 || ~4.0",
22 | "symfony/stopwatch": "^2.7 || ^3.0",
23 | "symfony/filesystem": "^2.7 || ^3.0",
24 | "symfony/dependency-injection": "^2.7 || ^3.0",
25 | "symfony/config": "^2.7 || ^3.0",
26 | "symfony/expression-language": "^2.7 || ^3.0"
27 | },
28 | "require-dev": {
29 | "phpunit/phpunit": "4.8.*",
30 | "mikey179/vfsstream": "^1.0"
31 | },
32 | "bin": ["bin/deprecation-detector"],
33 | "autoload": {
34 | "psr-4": {
35 | "SensioLabs\\DeprecationDetector\\": "src/"
36 | }
37 | },
38 | "autoload-dev": {
39 | "psr-4": {
40 | "SensioLabs\\DeprecationDetector\\Tests\\": "tests/"
41 | }
42 | },
43 | "abandoned": true
44 | }
45 |
--------------------------------------------------------------------------------
/examples/Arguments.php:
--------------------------------------------------------------------------------
1 | x = 10;
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/examples/Controller.php:
--------------------------------------------------------------------------------
1 | getEntityManager();
25 |
26 | $em = parent::getEntityManager();
27 |
28 | hello();
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/examples/FormType.php:
--------------------------------------------------------------------------------
1 | configureOptions($resolver);
41 | }
42 | }
43 | }
44 |
45 | namespace SomeType {
46 |
47 | use ExampleForm\AbstractType;
48 |
49 | class CustomFormType extends AbstractType
50 | {
51 | public function setDefaultOptions(\OptionsResolverInterface $resolver)
52 | {
53 | // DO ANYTHING
54 |
55 | parent::setDefaultOptions($resolver);
56 | }
57 | }
58 |
59 | }
60 |
--------------------------------------------------------------------------------
/examples/HelloWorld.php:
--------------------------------------------------------------------------------
1 | methodCall(&$b);
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/examples/deprecations.php:
--------------------------------------------------------------------------------
1 | otherClass->hello();
13 | $this->someClass->world();
14 | }
15 |
16 | public function __construct(OtherClass $x)
17 | {
18 | $this->someClass = $x;
19 | $this->otherClass = new OtherClass();
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/examples/dynamic/TrackingArguments.php:
--------------------------------------------------------------------------------
1 | hello();
8 |
9 | function fow(OtherClass $otherClass)
10 | {
11 | $otherClass->world();
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/examples/dynamic/TrackingVariables.php:
--------------------------------------------------------------------------------
1 | hello();
17 |
18 | OtherClass::world();
19 |
20 | $y::world();
21 | }
22 | }
23 |
24 | interface DeprecatedOtherInterface
25 | {
26 | /**
27 | * @deprecated don't implement deprecated methods
28 | */
29 | public function sayHello(
30 |
31 | namespace\SomeOtherClass $class, $ref);
32 | }
33 |
--------------------------------------------------------------------------------
/phpunit.xml.dist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 | ./tests/
7 |
8 |
9 |
10 |
11 |
12 |
13 | ./src
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/src/Console/Application.php:
--------------------------------------------------------------------------------
1 | add($checkCommand);
15 | $this->setDefaultCommand('check');
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Console/Output/VerboseProgressOutput.php:
--------------------------------------------------------------------------------
1 | progressBar = $progressBar;
36 | $this->verbose = $verbose;
37 | $this->label = $label;
38 | }
39 |
40 | /**
41 | * @param int $total
42 | */
43 | public function start($total)
44 | {
45 | if (!$this->verbose) {
46 | return;
47 | }
48 |
49 | $format = $this->label.': loading %max% files into memory, this can take some time';
50 | $this->progressBar->setFormat($format);
51 | $this->progressBar->start($total);
52 | }
53 |
54 | /**
55 | * @param int $current
56 | * @param PhpFileInfo $file
57 | */
58 | public function advance($current, PhpFileInfo $file)
59 | {
60 | if (!$this->verbose) {
61 | return;
62 | }
63 |
64 | if (1 === $current) {
65 | $format = '%message%'."\n".$this->label.': %current%/%max%';
66 | $this->progressBar->clear();
67 | $this->progressBar->setFormat($format);
68 | }
69 |
70 | $message = $file->getRelativePathname();
71 | $this->progressBar->setMessage($message);
72 | $this->progressBar->clear();
73 | $this->progressBar->advance();
74 | $this->progressBar->display();
75 | }
76 |
77 | public function end()
78 | {
79 | if (!$this->verbose) {
80 | return;
81 | }
82 |
83 | $this->progressBar->clear();
84 | $this->progressBar->finish();
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/src/FileInfo/Deprecation/ClassDeprecation.php:
--------------------------------------------------------------------------------
1 | name = $name;
24 | $this->comment = $comment;
25 | }
26 |
27 | /**
28 | * @return string
29 | */
30 | public function name()
31 | {
32 | return $this->name;
33 | }
34 |
35 | /**
36 | * @return string
37 | */
38 | public function comment()
39 | {
40 | return $this->comment;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/FileInfo/Deprecation/DeprecationInterface.php:
--------------------------------------------------------------------------------
1 | name = $name;
24 | $this->comment = $comment;
25 | }
26 |
27 | /**
28 | * @return string
29 | */
30 | public function name()
31 | {
32 | return $this->name;
33 | }
34 |
35 | /**
36 | * @return string
37 | */
38 | public function comment()
39 | {
40 | return $this->comment;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/FileInfo/Deprecation/InterfaceDeprecation.php:
--------------------------------------------------------------------------------
1 | name = $name;
24 | $this->comment = $comment;
25 | }
26 |
27 | /**
28 | * @return string
29 | */
30 | public function name()
31 | {
32 | return $this->name;
33 | }
34 |
35 | /**
36 | * @return string
37 | */
38 | public function comment()
39 | {
40 | return $this->comment;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/FileInfo/Deprecation/MethodDeprecation.php:
--------------------------------------------------------------------------------
1 | parentName = $parentName;
30 | $this->name = $name;
31 | $this->comment = $comment;
32 | }
33 |
34 | /**
35 | * @return string
36 | */
37 | public function parentName()
38 | {
39 | return $this->parentName;
40 | }
41 |
42 | /**
43 | * @return string
44 | */
45 | public function comment()
46 | {
47 | return $this->comment;
48 | }
49 |
50 | /**
51 | * @return string
52 | */
53 | public function name()
54 | {
55 | return $this->name;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/FileInfo/DeprecationCollectionInterface.php:
--------------------------------------------------------------------------------
1 | methodName = $methodName;
32 | $this->parentName = $parentName;
33 | $this->lineNumber = $lineNumber;
34 | }
35 |
36 | /**
37 | * @return string
38 | */
39 | public function name()
40 | {
41 | return $this->methodName;
42 | }
43 |
44 | /**
45 | * @return string
46 | */
47 | public function parentName()
48 | {
49 | return $this->parentName;
50 | }
51 |
52 | /**
53 | * @return int
54 | */
55 | public function getLineNumber()
56 | {
57 | return $this->lineNumber;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/FileInfo/Usage/ClassUsage.php:
--------------------------------------------------------------------------------
1 | className = $className;
24 | $this->lineNumber = $lineNumber;
25 | }
26 |
27 | /**
28 | * @return string
29 | */
30 | public function name()
31 | {
32 | return $this->className;
33 | }
34 |
35 | /**
36 | * @return int
37 | */
38 | public function getLineNumber()
39 | {
40 | return $this->lineNumber;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/FileInfo/Usage/DeprecatedLanguageUsage.php:
--------------------------------------------------------------------------------
1 | name = $name;
32 | $this->comment = $comment;
33 | $this->line = $line;
34 | }
35 |
36 | /**
37 | * @return string
38 | */
39 | public function comment()
40 | {
41 | return $this->comment;
42 | }
43 |
44 | /**
45 | * @return string
46 | */
47 | public function name()
48 | {
49 | return $this->name;
50 | }
51 |
52 | /**
53 | * @return int
54 | */
55 | public function getLineNumber()
56 | {
57 | return $this->line;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/FileInfo/Usage/FunctionUsage.php:
--------------------------------------------------------------------------------
1 | name = $name;
24 | $this->line = $line;
25 | }
26 |
27 | /**
28 | * @return string
29 | */
30 | public function name()
31 | {
32 | return $this->name;
33 | }
34 |
35 | /**
36 | * @return int
37 | */
38 | public function getLineNumber()
39 | {
40 | return $this->line;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/FileInfo/Usage/InterfaceUsage.php:
--------------------------------------------------------------------------------
1 | interfaceName = $interfaceName;
30 | $this->className = $className;
31 | $this->lineNumber = $lineNumber;
32 | }
33 |
34 | /**
35 | * @return string
36 | */
37 | public function name()
38 | {
39 | return $this->interfaceName;
40 | }
41 |
42 | /**
43 | * @return string
44 | */
45 | public function className()
46 | {
47 | return $this->className;
48 | }
49 |
50 | /**
51 | * @return int
52 | */
53 | public function getLineNumber()
54 | {
55 | return $this->lineNumber;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/FileInfo/Usage/MethodUsage.php:
--------------------------------------------------------------------------------
1 | methodName = $methodName;
36 | $this->className = $className;
37 | $this->lineNumber = $lineNumber;
38 | $this->isStatic = $isStatic;
39 | }
40 |
41 | /**
42 | * @return string
43 | */
44 | public function name()
45 | {
46 | return $this->methodName;
47 | }
48 |
49 | /**
50 | * @return string
51 | */
52 | public function className()
53 | {
54 | return $this->className;
55 | }
56 |
57 | /**
58 | * @return int
59 | */
60 | public function getLineNumber()
61 | {
62 | return $this->lineNumber;
63 | }
64 |
65 | /**
66 | * @return bool
67 | */
68 | public function isStatic()
69 | {
70 | return $this->isStatic;
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/FileInfo/Usage/SuperTypeUsage.php:
--------------------------------------------------------------------------------
1 | superTypeName = $superTypeName;
30 | $this->className = $className;
31 | $this->lineNumber = $lineNumber;
32 | }
33 |
34 | /**
35 | * @return string
36 | */
37 | public function name()
38 | {
39 | return $this->superTypeName;
40 | }
41 |
42 | /**
43 | * @return string
44 | */
45 | public function className()
46 | {
47 | return $this->className;
48 | }
49 |
50 | /**
51 | * @return int
52 | */
53 | public function getLineNumber()
54 | {
55 | return $this->lineNumber;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/FileInfo/Usage/TypeHintUsage.php:
--------------------------------------------------------------------------------
1 | typeHintName = $typeHintName;
24 | $this->lineNumber = $lineNumber;
25 | }
26 |
27 | /**
28 | * @return string
29 | */
30 | public function name()
31 | {
32 | return $this->typeHintName;
33 | }
34 |
35 | /**
36 | * @return int
37 | */
38 | public function getLineNumber()
39 | {
40 | return $this->lineNumber;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/FileInfo/Usage/UsageInterface.php:
--------------------------------------------------------------------------------
1 | name('*.php')
14 | ->contains('@deprecated')
15 | ->exclude('vendor')
16 | ->exclude('Tests')
17 | ->exclude('Test');
18 |
19 | return $finder;
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Finder/FinderFactoryInterface.php:
--------------------------------------------------------------------------------
1 | parser = $parser;
35 | $this->progressOutput = $progressOutput;
36 | $this->finderFactory = $finderFactory;
37 | }
38 |
39 | /**
40 | * @param string $path
41 | *
42 | * @return Result
43 | */
44 | public function parsePhpFiles($path)
45 | {
46 | $files = $this->finderFactory->createFinder()->in($path);
47 | $parsedFiles = array();
48 | $parserErrors = array();
49 |
50 | $this->progressOutput->start($fileCount = $files->count());
51 |
52 | $i = 0;
53 | foreach ($files->getIterator() as $file) {
54 | $file = PhpFileInfo::create($file);
55 |
56 | try {
57 | $this->progressOutput->advance(++$i, $file);
58 | $this->parser->parseFile($file);
59 | } catch (Error $ex) {
60 | $raw = $ex->getRawMessage().' in file '.$file;
61 | $ex->setRawMessage($raw);
62 | $parserErrors[] = $ex;
63 | }
64 |
65 | $parsedFiles[] = $file;
66 | }
67 |
68 | $this->progressOutput->end();
69 |
70 | return new Result($parsedFiles, $parserErrors, $fileCount);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/Finder/Result.php:
--------------------------------------------------------------------------------
1 | files = $files;
24 | $this->errors = $errors;
25 | $this->fileCount = $fileCount;
26 | }
27 |
28 | public function parsedFiles()
29 | {
30 | return $this->files;
31 | }
32 |
33 | public function parserErrors()
34 | {
35 | return $this->errors;
36 | }
37 |
38 | public function fileCount()
39 | {
40 | return $this->fileCount;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Finder/UsageFinderFactory.php:
--------------------------------------------------------------------------------
1 | name('*.php')
14 | ->exclude('vendor')
15 | ->exclude('Tests')
16 | ->exclude('Test');
17 |
18 | return $finder;
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Parser/DeprecationParser.php:
--------------------------------------------------------------------------------
1 | traverser = $baseTraverser;
31 |
32 | array_map(array($this, 'addDeprecationVisitor'), $visitors);
33 | }
34 |
35 | /**
36 | * @param DeprecationVisitorInterface $visitor
37 | */
38 | public function addDeprecationVisitor(DeprecationVisitorInterface $visitor)
39 | {
40 | $this->deprecationVisitors[] = $visitor;
41 | $this->traverser->addVisitor($visitor);
42 | }
43 |
44 | /**
45 | * @param PhpFileInfo $phpFileInfo
46 | *
47 | * @return PhpFileInfo
48 | */
49 | public function parseFile(PhpFileInfo $phpFileInfo)
50 | {
51 | foreach ($this->deprecationVisitors as $visitor) {
52 | $visitor->setPhpFileInfo($phpFileInfo);
53 | }
54 |
55 | $this->traverser->traverse($this->parse($phpFileInfo->getContents()));
56 |
57 | return $phpFileInfo;
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/src/Parser/ParserInterface.php:
--------------------------------------------------------------------------------
1 | nameResolver = $baseTraverser;
50 | $this->staticTraverser = $staticTraverser;
51 | foreach ($staticAnalysisVisitors as $visitor) {
52 | $this->staticTraverser->addVisitor($visitor);
53 | }
54 |
55 | $this->violationTraverser = $violationTraverser;
56 | $this->violationVisitors = $violationVisitors;
57 | foreach ($violationVisitors as $visitor) {
58 | $this->violationTraverser->addVisitor($visitor);
59 | }
60 | }
61 |
62 | /**
63 | * @param PhpFileInfo $phpFileInfo
64 | *
65 | * @return PhpFileInfo
66 | */
67 | public function parseFile(PhpFileInfo $phpFileInfo)
68 | {
69 | $nodes = $this->parse($phpFileInfo->getContents());
70 | $nodes = $this->nameResolver->traverse($nodes);
71 | $nodes = $this->staticTraverser->traverse($nodes);
72 |
73 | foreach ($this->violationVisitors as $visitor) {
74 | $visitor->setPhpFileInfo($phpFileInfo);
75 | }
76 |
77 | $this->violationTraverser->traverse($nodes);
78 |
79 | return $phpFileInfo;
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/src/RuleSet/Cache.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class Cache
14 | {
15 | /**
16 | * @var string
17 | */
18 | protected $cacheDir;
19 |
20 | /**
21 | * @var bool
22 | */
23 | protected $enabled;
24 |
25 | /**
26 | * @var Filesystem
27 | */
28 | protected $filesystem;
29 |
30 | /**
31 | * @param Filesystem $filesystem
32 | * @param bool|true $enabled
33 | * @param string $cacheDir
34 | */
35 | public function __construct(Filesystem $filesystem, $enabled = true, $cacheDir = '.rules/')
36 | {
37 | $this->filesystem = $filesystem;
38 | $this->enabled = $enabled;
39 | $this->setCacheDir($cacheDir);
40 | }
41 |
42 | /**
43 | * @param string $cacheDir
44 | */
45 | public function setCacheDir($cacheDir)
46 | {
47 | $this->cacheDir = (substr($cacheDir, -1) === '/' ? $cacheDir : $cacheDir.'/');
48 | }
49 |
50 | /**
51 | * call to disable the cache.
52 | */
53 | public function disable()
54 | {
55 | $this->enabled = false;
56 | }
57 |
58 | /**
59 | * @return bool
60 | */
61 | public function isEnabled()
62 | {
63 | return $this->enabled;
64 | }
65 |
66 | /**
67 | * @param string $key
68 | *
69 | * @return bool
70 | */
71 | public function has($key)
72 | {
73 | return $this->enabled && $this->filesystem->exists($this->cacheDir.$key);
74 | }
75 |
76 | /**
77 | * @param string $key
78 | * @param RuleSet|null $ruleSet
79 | */
80 | public function cacheRuleSet($key, $ruleSet)
81 | {
82 | if ($this->enabled) {
83 | $this->filesystem->dumpFile($this->cacheDir.$key, serialize($ruleSet));
84 | }
85 | }
86 |
87 | /**
88 | * @param string $key
89 | *
90 | * @return RuleSet|null
91 | */
92 | public function getCachedRuleSet($key)
93 | {
94 | if (!$this->enabled || !$this->filesystem->exists($this->cacheDir.$key)) {
95 | return;
96 | }
97 |
98 | $file = new SplFileInfo($this->cacheDir.$key, null, null);
99 |
100 | return unserialize($file->getContents());
101 | }
102 | }
103 |
--------------------------------------------------------------------------------
/src/RuleSet/DirectoryTraverser.php:
--------------------------------------------------------------------------------
1 | finder = $finder;
20 | }
21 |
22 | /**
23 | * @param string $path
24 | * @param RuleSet $ruleSet
25 | *
26 | * @return RuleSet
27 | */
28 | public function traverse($path, RuleSet $ruleSet = null)
29 | {
30 | $result = $this->finder->parsePhpFiles($path);
31 |
32 | if (!$ruleSet instanceof RuleSet) {
33 | $ruleSet = new RuleSet();
34 | }
35 |
36 | foreach ($result->parsedFiles() as $file) {
37 | if ($file->hasDeprecations()) {
38 | $ruleSet->merge($file);
39 | }
40 | }
41 |
42 | return $ruleSet;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/RuleSet/Loader/Composer/Composer.php:
--------------------------------------------------------------------------------
1 | packages = $packages;
30 | $this->devPackages = $devPackages;
31 | $this->includeDev = $includeDev;
32 | }
33 |
34 | /**
35 | * @return Package[]
36 | */
37 | public function getPackages()
38 | {
39 | if (true === $this->includeDev) {
40 | return array_merge($this->packages, $this->devPackages);
41 | }
42 |
43 | return $this->packages;
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/src/RuleSet/Loader/Composer/ComposerFactory.php:
--------------------------------------------------------------------------------
1 | getContents(), true);
27 |
28 | if (json_last_error() != JSON_ERROR_NONE) {
29 | throw new ComposerFileIsInvalidException($lockPath);
30 | }
31 |
32 | $packages = array();
33 | foreach ($decodedData['packages'] as $package) {
34 | $packages[] = Package::fromArray($package);
35 | }
36 |
37 | $devPackages = array();
38 | foreach ($decodedData['packages-dev'] as $package) {
39 | $devPackages[] = Package::fromArray($package);
40 | }
41 |
42 | return new Composer($packages, $devPackages, true);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/RuleSet/Loader/Composer/ComposerLoader.php:
--------------------------------------------------------------------------------
1 | traverser = $traverser;
40 | $this->cache = $cache;
41 | $this->factory = $factory;
42 | }
43 |
44 | /**
45 | * {@inheritdoc}
46 | */
47 | public function loadRuleSet($lock)
48 | {
49 | try {
50 | $composer = $this->factory->fromLock($lock);
51 | } catch (ComposerException $e) {
52 | throw new CouldNotLoadRuleSetException($e->getMessage());
53 | }
54 |
55 | $ruleSet = new RuleSet();
56 | foreach ($composer->getPackages() as $package) {
57 | $ruleSet->merge($this->loadPackageRuleSet($package));
58 | }
59 |
60 | return $ruleSet;
61 | }
62 |
63 | /**
64 | * @param Package $package
65 | *
66 | * @return RuleSet
67 | */
68 | private function loadPackageRuleSet(Package $package)
69 | {
70 | $ruleSet = new RuleSet();
71 | $key = $package->generatePackageKey();
72 |
73 | if ($this->cache->has($key)) {
74 | $ruleSet = $this->cache->getCachedRuleSet($key);
75 | } elseif (is_dir($path = $package->getPackagePath(self::PACKAGE_PATH))) {
76 | $ruleSet = $this->traverser->traverse($path);
77 | $this->cache->cacheRuleSet($key, $ruleSet);
78 | } else {
79 | // there is no vendor package in the given path
80 | }
81 |
82 | return $ruleSet;
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/src/RuleSet/Loader/Composer/Exception/ComposerException.php:
--------------------------------------------------------------------------------
1 | name = $name;
24 | $this->version = $version;
25 | }
26 |
27 | /**
28 | * @param array $package
29 | *
30 | * @return Package
31 | */
32 | public static function fromArray(array $package)
33 | {
34 | return new self(
35 | $package['name'],
36 | $package['version']
37 | );
38 | }
39 |
40 | /**
41 | * @return string
42 | */
43 | public function generatePackageKey()
44 | {
45 | return str_replace(array('/', '\\', ':'), '_', $this->name).'_'.$this->version;
46 | }
47 |
48 | /**
49 | * @param string $prefix
50 | *
51 | * @return string
52 | */
53 | public function getPackagePath($prefix)
54 | {
55 | return $prefix.$this->name;
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/src/RuleSet/Loader/CouldNotLoadRuleSetException.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class DirectoryLoader implements LoaderInterface
14 | {
15 | /**
16 | * @var DirectoryTraverser
17 | */
18 | protected $traverser;
19 |
20 | /**
21 | * @var Cache
22 | */
23 | protected $cache;
24 |
25 | /**
26 | * @param DirectoryTraverser $traverser
27 | * @param Cache $cache
28 | */
29 | public function __construct(DirectoryTraverser $traverser, Cache $cache)
30 | {
31 | $this->traverser = $traverser;
32 | $this->cache = $cache;
33 | }
34 |
35 | /**
36 | * {@inheritdoc}
37 | */
38 | public function loadRuleSet($path)
39 | {
40 | $key = $this->generateDirectoryKey($path);
41 |
42 | if ($this->cache->has($key)) {
43 | return $this->cache->getCachedRuleSet($key);
44 | }
45 |
46 | $ruleSet = $this->traverser->traverse($path);
47 | $this->cache->cacheRuleSet($key, $ruleSet);
48 |
49 | return $ruleSet;
50 | }
51 |
52 | /**
53 | * @param string $path
54 | *
55 | * @return string
56 | */
57 | private function generateDirectoryKey($path)
58 | {
59 | return str_replace(array('/', '\\', ':'), '_', $path);
60 | }
61 | }
62 |
--------------------------------------------------------------------------------
/src/RuleSet/Loader/FileLoader.php:
--------------------------------------------------------------------------------
1 |
12 | */
13 | class FileLoader implements LoaderInterface
14 | {
15 | /**
16 | * {@inheritdoc}
17 | */
18 | public function loadRuleSet($path)
19 | {
20 | if (!is_file($path)) {
21 | throw new CouldNotLoadRuleSetException(sprintf(
22 | 'Ruleset "%s" does not exist, aborting.',
23 | $path
24 | )
25 | );
26 | }
27 |
28 | $file = new SplFileInfo($path, null, null);
29 | $ruleSet = unserialize($file->getContents());
30 |
31 | if (!$ruleSet instanceof RuleSet) {
32 | throw new CouldNotLoadRuleSetException(sprintf(
33 | 'Ruleset "%s" is invalid, aborting.',
34 | $path
35 | )
36 | );
37 | }
38 |
39 | return $ruleSet;
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/RuleSet/Loader/LoaderInterface.php:
--------------------------------------------------------------------------------
1 |
11 | */
12 | interface LoaderInterface
13 | {
14 | /**
15 | * @param string $path
16 | *
17 | * @return RuleSet
18 | *
19 | * @throws CouldNotLoadRuleSetException
20 | */
21 | public function loadRuleSet($path);
22 | }
23 |
--------------------------------------------------------------------------------
/src/TypeGuessing/ConstructorResolver/Visitor/ConstructorResolverVisitor.php:
--------------------------------------------------------------------------------
1 | constructorResolver = $constructorResolver;
17 | }
18 |
19 | public function enterNode(Node $node)
20 | {
21 | if ($node instanceof Node\Stmt\Class_) {
22 | return $this->constructorResolver->resolveConstructor($node);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/TypeGuessing/SymbolTable/ComposedResolver.php:
--------------------------------------------------------------------------------
1 | resolver = array();
18 | }
19 |
20 | /**
21 | * @param ResolverInterface $resolver
22 | */
23 | public function addResolver(ResolverInterface $resolver)
24 | {
25 | $this->resolver[] = $resolver;
26 | }
27 |
28 | public function resolveVariableType(Node $node)
29 | {
30 | foreach ($this->resolver as $resolver) {
31 | $resolver->resolveVariableType($node);
32 | }
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/TypeGuessing/SymbolTable/Resolver/ArgumentResolver.php:
--------------------------------------------------------------------------------
1 | table = $table;
21 | }
22 |
23 | /**
24 | * {@inheritdoc}
25 | */
26 | public function resolveVariableType(Node $node)
27 | {
28 | if ($node instanceof Node\Param && $node->type instanceof Node\Name) {
29 | $this->table->setSymbol($node->name, $node->type->toString());
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/TypeGuessing/SymbolTable/Resolver/ReattachStateToProperty.php:
--------------------------------------------------------------------------------
1 | prop = new SomeClass(); (Another resolver will set the type of $this->prop to the AST)
16 | * $this->prop->someMethod(); (The ReattachStateToProperty will set the same guessedType to the $this->prop AST node again)
17 | */
18 | class ReattachStateToProperty implements ResolverInterface
19 | {
20 | /**
21 | * @var SymbolTable
22 | */
23 | private $table;
24 |
25 | /**
26 | * @param SymbolTable $table
27 | */
28 | public function __construct(SymbolTable $table)
29 | {
30 | $this->table = $table;
31 | }
32 |
33 | /**
34 | * {@inheritdoc}
35 | */
36 | public function resolveVariableType(Node $node)
37 | {
38 | if ($node instanceof Node\Expr\PropertyFetch) {
39 | // $this->someProperty
40 | if ($node->var instanceof Node\Expr\Variable && $node->var->name === 'this') {
41 | $node->setAttribute('guessedType', $this->table->lookUpClassProperty($node->name)->type());
42 | }
43 |
44 | // $x->someProperty
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/TypeGuessing/SymbolTable/Resolver/ReattachStateToVariable.php:
--------------------------------------------------------------------------------
1 | someMethod(); (The ReattachStateToVariable will set the same guessedType to the $var AST node again)
17 | */
18 | class ReattachStateToVariable implements ResolverInterface
19 | {
20 | /**
21 | * @var SymbolTable
22 | */
23 | private $table;
24 |
25 | /**
26 | * @param SymbolTable $table
27 | */
28 | public function __construct(SymbolTable $table)
29 | {
30 | $this->table = $table;
31 | }
32 |
33 | /**
34 | * {@inheritdoc}
35 | */
36 | public function resolveVariableType(Node $node)
37 | {
38 | if ($node instanceof Node\Expr\Variable) {
39 | $node->setAttribute('guessedType', $this->table->lookUp($node->name)->type());
40 | }
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/TypeGuessing/SymbolTable/Resolver/ResolverInterface.php:
--------------------------------------------------------------------------------
1 | prop; (attaches guessedType of $this->prop to the $var AST node)
18 | */
19 | class VariableAssignResolver implements ResolverInterface
20 | {
21 | /**
22 | * @var SymbolTable
23 | */
24 | private $table;
25 |
26 | /**
27 | * @param SymbolTable $table
28 | */
29 | public function __construct(SymbolTable $table)
30 | {
31 | $this->table = $table;
32 | }
33 |
34 | /**
35 | * {@inheritdoc}
36 | */
37 | public function resolveVariableType(Node $node)
38 | {
39 | // $x = ...
40 | if (!$node instanceof Node\Expr\Assign
41 | || !$node->var instanceof Node\Expr\Variable) {
42 | return;
43 | }
44 |
45 | // skips variable names like ${$node->nodeName}
46 | if (!is_string($node->var->name)) {
47 | return;
48 | }
49 |
50 | // $x = new X();
51 | if ($node->expr instanceof Node\Expr\New_) {
52 | if ($node->expr->class instanceof Node\Name) {
53 | $type = $node->expr->class->toString();
54 | $this->table->setSymbol($node->var->name, $type);
55 | $node->var->setAttribute('guessedType', $type);
56 | }
57 | }
58 |
59 | // $x = $y;
60 | if ($node->expr instanceof Node\Expr\Variable) {
61 | $type = $this->table->lookUp($node->expr->name)->type();
62 | $node->var->setAttribute('guessedType', $type);
63 | $this->table->setSymbol($node->var->name, $type);
64 | }
65 |
66 | // $x = $this->x
67 | if ($node->expr instanceof Node\Expr\PropertyFetch) {
68 | $type = $this->table->lookUpClassProperty($node->expr->name)->type();
69 | $node->var->setAttribute('guessedType', $type);
70 | $this->table->setSymbol($node->var->name, $type);
71 | }
72 | }
73 | }
74 |
--------------------------------------------------------------------------------
/src/TypeGuessing/SymbolTable/Symbol.php:
--------------------------------------------------------------------------------
1 | symbol = $symbol;
24 | $this->type = $type;
25 | }
26 |
27 | /**
28 | * @return string
29 | */
30 | public function symbol()
31 | {
32 | return $this->symbol;
33 | }
34 |
35 | /**
36 | * @return string
37 | */
38 | public function type()
39 | {
40 | return $this->type;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/TypeGuessing/SymbolTable/TableScope.php:
--------------------------------------------------------------------------------
1 | layerType = $layerType;
28 | $this->symbols = array();
29 | }
30 |
31 | /**
32 | * @param Symbol $symbol
33 | */
34 | public function setSymbol(Symbol $symbol)
35 | {
36 | $this->symbols[$symbol->symbol()] = $symbol;
37 | }
38 |
39 | /**
40 | * @param string $symbolName
41 | *
42 | * @return Symbol
43 | */
44 | public function findSymbol($symbolName)
45 | {
46 | /** @var $symbol Symbol */
47 | foreach ($this->symbols as $symbol) {
48 | if ($symbol->symbol() === $symbolName) {
49 | return $symbol;
50 | }
51 | }
52 |
53 | return;
54 | }
55 |
56 | /**
57 | * @return string
58 | */
59 | public function scope()
60 | {
61 | return $this->layerType;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/TypeGuessing/Symfony/ContainerReader.php:
--------------------------------------------------------------------------------
1 | container = new ContainerBuilder();
33 |
34 | try {
35 | $loader = new XmlFileLoader($this->container, new FileLocator(dirname($containerPath)));
36 | $loader->load(basename($containerPath));
37 |
38 | return true;
39 | } catch (\Exception $e) {
40 | return false;
41 | }
42 | }
43 |
44 | /**
45 | * @param $id
46 | *
47 | * @return bool|null
48 | */
49 | public function has($id)
50 | {
51 | if (null === $this->container) {
52 | return;
53 | }
54 |
55 | return $this->container->hasDefinition($id);
56 | }
57 |
58 | /**
59 | * @param $id
60 | *
61 | * @return string|null
62 | */
63 | public function get($id)
64 | {
65 | if (!$this->has($id)) {
66 | return;
67 | }
68 |
69 | return $this->container->findDefinition($id)->getClass();
70 | }
71 |
72 | /**
73 | * @param $name
74 | * @param $args
75 | *
76 | * @throws \BadMethodCallException
77 | */
78 | public function __call($name, $args)
79 | {
80 | throw new \BadMethodCallException(
81 | 'Unlike Symfony container SymfonyContainerReader is read only and just implements the '
82 | .'methods "has" and "get".'
83 | );
84 | }
85 | }
86 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/Console/BaseRenderer.php:
--------------------------------------------------------------------------------
1 | output = $output;
30 | $this->messageHelper = $messageHelper;
31 | }
32 |
33 | /**
34 | * @param Violation[] $violations
35 | * @param Error[] $errors
36 | */
37 | public function renderViolations(array $violations, array $errors)
38 | {
39 | $this->printViolations($violations);
40 | $this->printErrors($errors);
41 | }
42 |
43 | /**
44 | * @param Violation[] $violations
45 | */
46 | abstract protected function printViolations(array $violations);
47 |
48 | /**
49 | * @param Error[] $errors
50 | */
51 | protected function printErrors(array $errors)
52 | {
53 | if (0 === count($errors)) {
54 | return;
55 | }
56 |
57 | $this->output->writeln('');
58 | $this->output->writeln('Your project contains invalid code:');
59 | foreach ($errors as $error) {
60 | $this->output->writeln(
61 | sprintf(
62 | '%s',
63 | $error->getRawMessage()
64 | )
65 | );
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/Console/DefaultRenderer.php:
--------------------------------------------------------------------------------
1 | output);
34 | $table->setHeaders(array('#', 'Usage', 'Line', 'Comment'));
35 |
36 | $tmpFile = null;
37 | foreach ($violations as $i => $violation) {
38 | if ($tmpFile !== $violation->getFile()) {
39 | $tmpFile = $violation->getFile();
40 | if (0 !== $i) {
41 | $table->addRow(new TableSeparator());
42 | }
43 | $table->addRow($this->getFileHeader($tmpFile));
44 | $table->addRow(new TableSeparator());
45 | }
46 |
47 | $table->addRow(array(
48 | ++$i,
49 | $this->messageHelper->getViolationMessage($violation),
50 | $violation->getLine(),
51 | $violation->getComment(),
52 | ));
53 | }
54 |
55 | $table->render();
56 | }
57 |
58 | /**
59 | * @param PhpFileInfo $file
60 | *
61 | * @return TableCell[]
62 | */
63 | protected function getFileHeader(PhpFileInfo $file)
64 | {
65 | $cell = new TableCell(
66 | sprintf('%s', $file->getPathname()),
67 | array('colspan' => 3)
68 | );
69 |
70 | return array(new TableCell(), $cell);
71 | }
72 | }
73 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/Console/SimpleRenderer.php:
--------------------------------------------------------------------------------
1 | $violation) {
31 | if ($tmpFile !== $violation->getFile()) {
32 | $tmpFile = $violation->getFile();
33 | if (0 !== $i) {
34 | $this->output->writeln('');
35 | }
36 | $this->output->writeln($tmpFile->getRelativePathname());
37 | }
38 |
39 | $this->output->writeln(sprintf(
40 | 'Nr. %d line %d: %s',
41 | ++$i,
42 | $violation->getLine(),
43 | $this->messageHelper->getViolationMessage($violation)
44 | ));
45 | }
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/Html/Renderer.php:
--------------------------------------------------------------------------------
1 |
18 | */
19 | class Renderer implements RendererInterface
20 | {
21 | /**
22 | * @var MessageHelper
23 | */
24 | private $messageHelper;
25 | /**
26 | * @var string
27 | */
28 | private $outputFilename;
29 | /**
30 | * @var Filesystem
31 | */
32 | private $fileSystem;
33 |
34 | /**
35 | * @param MessageHelper $messageHelper
36 | * @param Filesystem $filesystem
37 | * @param string $outputFilename
38 | */
39 | public function __construct(
40 | MessageHelper $messageHelper,
41 | Filesystem $filesystem,
42 | $outputFilename
43 | ) {
44 | $this->messageHelper = $messageHelper;
45 | $this->fileSystem = $filesystem;
46 | $this->outputFilename = $outputFilename;
47 | }
48 |
49 | /**
50 | * @param Violation[] $violations
51 | * @param Error[] $errors
52 | */
53 | public function renderViolations(array $violations, array $errors)
54 | {
55 | $orderedViolations = array();
56 | // sorting and grouping violations
57 | foreach ($violations as $violation) {
58 | $key = $violation->getFile()->getPathname();
59 | if (!array_key_exists($key, $orderedViolations)) {
60 | $orderedViolations[$key] = array();
61 | }
62 |
63 | $fileViolation['message'] = $this->messageHelper->getViolationMessage($violation);
64 | $fileViolation['line'] = $violation->getLine();
65 | $fileViolation['comment'] = $violation->getComment();
66 | $orderedViolations[$key][] = $fileViolation;
67 | }
68 |
69 | ob_start();
70 | include __DIR__.'/../../../Resources/templates/htmlTable.phtml';
71 | $htmlOutput = ob_get_clean();
72 |
73 | $this->fileSystem->mkdir(dirname($this->outputFilename));
74 |
75 | file_put_contents($this->outputFilename, $htmlOutput);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/Html/RendererFactory.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | class RendererFactory
16 | {
17 | private $messageHelper;
18 | private $filesystem;
19 |
20 | public function __construct(MessageHelper $messageHelper, Filesystem $filesystem)
21 | {
22 | $this->messageHelper = $messageHelper;
23 | $this->filesystem = $filesystem;
24 | }
25 |
26 | public function createHtmlOutputRenderer($outputFile)
27 | {
28 | return new Renderer($this->messageHelper, $this->filesystem, $outputFile);
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/MessageHelper/Message/BaseViolationMessage.php:
--------------------------------------------------------------------------------
1 | usageName = $usageName;
17 | }
18 |
19 | public function supports(UsageInterface $usage)
20 | {
21 | return $usage instanceof $this->usageName;
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/MessageHelper/Message/ClassViolationMessage.php:
--------------------------------------------------------------------------------
1 | %s',
25 | $usage->name()
26 | );
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/MessageHelper/Message/FunctionViolationMessage.php:
--------------------------------------------------------------------------------
1 | %s()',
25 | $usage->name()
26 | );
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/MessageHelper/Message/InterfaceViolationMessage.php:
--------------------------------------------------------------------------------
1 | %s',
25 | $usage->name()
26 | );
27 |
28 | $className = $usage->className();
29 |
30 | return empty($className)
31 | ? $violationInfo
32 | : sprintf('%s by class %s', $violationInfo, $className);
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/MessageHelper/Message/LanguageDeprecationMessage.php:
--------------------------------------------------------------------------------
1 | %s',
25 | $usage->name()
26 | );
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/MessageHelper/Message/MethodDefinitionViolationMessage.php:
--------------------------------------------------------------------------------
1 | %s->%s()',
25 | $usage->parentName(),
26 | $usage->name()
27 | );
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/MessageHelper/Message/MethodViolationMessage.php:
--------------------------------------------------------------------------------
1 | isStatic() === true) ?
24 | sprintf(
25 | 'static method %s::%s()',
26 | $usage->className(),
27 | $usage->name()
28 | ) :
29 | sprintf(
30 | 'method %s->%s()',
31 | $usage->className(),
32 | $usage->name()
33 | );
34 |
35 | $violationInfo = sprintf(
36 | 'Calling deprecated %s',
37 | $message
38 | );
39 |
40 | return $violationInfo;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/MessageHelper/Message/SuperTypeViolationMessage.php:
--------------------------------------------------------------------------------
1 | %s by class %s',
25 | $usage->name(),
26 | $usage->className()
27 | );
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/MessageHelper/Message/ViolationMessageInterface.php:
--------------------------------------------------------------------------------
1 | violationMessages = $violationMessages;
21 | }
22 |
23 | /**
24 | * @param ViolationMessageInterface $message
25 | */
26 | public function addViolationMessage(ViolationMessageInterface $message)
27 | {
28 | $this->violationMessages[] = $message;
29 | }
30 |
31 | public function getViolationMessage(Violation $violation)
32 | {
33 | foreach ($this->violationMessages as $message) {
34 | if ($message->supports($violation->getUsage())) {
35 | return $message->message($violation->getUsage());
36 | }
37 | }
38 |
39 | // fallback
40 | $classNamespace = explode('\\', get_class($violation->getUsage()));
41 |
42 | return sprintf(
43 | 'Deprecated %s %s',
44 | array_pop($classNamespace),
45 | $violation->getUsage()->name()
46 | );
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Violation/Renderer/RendererInterface.php:
--------------------------------------------------------------------------------
1 | file = $file;
38 | $this->line = $usage->getLineNumber();
39 | $this->usage = $usage;
40 | $this->comment = $comment;
41 | }
42 |
43 | /**
44 | * @return PhpFileInfo
45 | */
46 | public function getFile()
47 | {
48 | return $this->file;
49 | }
50 |
51 | /**
52 | * @return int
53 | */
54 | public function getLine()
55 | {
56 | return $this->line;
57 | }
58 |
59 | /**
60 | * @return string
61 | */
62 | public function getComment()
63 | {
64 | return $this->comment;
65 | }
66 |
67 | /**
68 | * @return UsageInterface
69 | */
70 | public function getUsage()
71 | {
72 | return $this->usage;
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/src/Violation/ViolationChecker/ClassViolationChecker.php:
--------------------------------------------------------------------------------
1 | classUsages() as $classUsage) {
19 | if ($ruleSet->hasClass($classUsage->name())) {
20 | $violations[] = new Violation(
21 | $classUsage,
22 | $phpFileInfo,
23 | $ruleSet->getClass($classUsage->name())->comment()
24 | );
25 | }
26 | }
27 |
28 | return $violations;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Violation/ViolationChecker/ComposedViolationChecker.php:
--------------------------------------------------------------------------------
1 | violationCheckers = $violationCheckers;
21 | }
22 |
23 | /**
24 | * {@inheritdoc}
25 | */
26 | public function check(PhpFileInfo $phpFileInfo, RuleSet $ruleSet)
27 | {
28 | $violations = array_map(function (ViolationCheckerInterface $checker) use ($phpFileInfo, $ruleSet) {
29 | try {
30 | return $checker->check($phpFileInfo, $ruleSet);
31 | } catch (\Exception $e) {
32 | # TODO.
33 | return array();
34 | }
35 | }, $this->violationCheckers);
36 |
37 | $result = array();
38 | array_walk($violations, function ($vio) use (&$result) {
39 | $result = array_merge($result, $vio);
40 | });
41 |
42 | return $result;
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/src/Violation/ViolationChecker/FunctionViolationChecker.php:
--------------------------------------------------------------------------------
1 | getFunctionUsages() as $functionUsage) {
19 | if ($ruleSet->hasFunction($functionUsage->name())) {
20 | $violations[] = new Violation(
21 | $functionUsage,
22 | $phpFileInfo,
23 | $ruleSet->getFunction($functionUsage->name())->comment()
24 | );
25 | }
26 | }
27 |
28 | return $violations;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Violation/ViolationChecker/InterfaceViolationChecker.php:
--------------------------------------------------------------------------------
1 | interfaceUsages() as $interfaceUsageGroup) {
19 | foreach ($interfaceUsageGroup as $interfaceUsage) {
20 | if ($ruleSet->hasInterface($interfaceUsage->name())) {
21 | $violations[] = new Violation(
22 | $interfaceUsage,
23 | $phpFileInfo,
24 | $ruleSet->getInterface($interfaceUsage->name())->comment()
25 | );
26 | }
27 | }
28 | }
29 |
30 | return $violations;
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/src/Violation/ViolationChecker/LanguageViolationChecker.php:
--------------------------------------------------------------------------------
1 | getDeprecatedLanguageUsages() as $deprecatedLanguageUsage) {
19 | $violations[] = new Violation(
20 | $deprecatedLanguageUsage,
21 | $phpFileInfo,
22 | $deprecatedLanguageUsage->comment()
23 | );
24 | }
25 |
26 | return $violations;
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Violation/ViolationChecker/MethodDefinitionViolationChecker.php:
--------------------------------------------------------------------------------
1 | ancestorResolver = $ancestorResolver;
23 | }
24 |
25 | /**
26 | * {@inheritdoc}
27 | */
28 | public function check(PhpFileInfo $phpFileInfo, RuleSet $ruleSet)
29 | {
30 | $violations = array();
31 |
32 | foreach ($phpFileInfo->methodDefinitions() as $methodDefinition) {
33 | $ancestors = $this->ancestorResolver->getClassAncestors($phpFileInfo, $methodDefinition->parentName());
34 |
35 | foreach ($ancestors as $ancestor) {
36 | if ($ruleSet->hasMethod($methodDefinition->name(), $ancestor)) {
37 | $violations[] = new Violation(
38 | $methodDefinition,
39 | $phpFileInfo,
40 | $ruleSet->getMethod($methodDefinition->name(), $ancestor)->comment()
41 | );
42 | }
43 | }
44 | }
45 |
46 | return $violations;
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/src/Violation/ViolationChecker/MethodViolationChecker.php:
--------------------------------------------------------------------------------
1 | ancestorResolver = $ancestorResolver;
24 | }
25 |
26 | /**
27 | * {@inheritdoc}
28 | */
29 | public function check(PhpFileInfo $phpFileInfo, RuleSet $ruleSet)
30 | {
31 | $violations = array();
32 |
33 | foreach ($phpFileInfo->methodUsages() as $methodUsage) {
34 | $className = $methodUsage->className();
35 |
36 | if ($ruleSet->hasMethod($methodUsage->name(), $className)) {
37 | $violations[] = new Violation(
38 | $methodUsage,
39 | $phpFileInfo,
40 | $ruleSet->getMethod($methodUsage->name(), $className)->comment()
41 | );
42 | }
43 |
44 | $ancestors = $this->ancestorResolver->getClassAncestors($phpFileInfo, $methodUsage->className());
45 |
46 | foreach ($ancestors as $ancestor) {
47 | if ($ruleSet->hasMethod($methodUsage->name(), $ancestor)) {
48 | $violations[] = new Violation(
49 | new MethodUsage(
50 | $methodUsage->name(),
51 | $ancestor,
52 | $methodUsage->getLineNumber(),
53 | $methodUsage->isStatic()
54 | ),
55 | $phpFileInfo,
56 | $ruleSet->getMethod($methodUsage->name(), $ancestor)->comment()
57 | );
58 | }
59 | }
60 | }
61 |
62 | return $violations;
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/src/Violation/ViolationChecker/SuperTypeViolationChecker.php:
--------------------------------------------------------------------------------
1 | superTypeUsages() as $superTypeUsage) {
19 | if ($ruleSet->hasClass($superTypeUsage->name())) {
20 | $violations[] = new Violation(
21 | $superTypeUsage,
22 | $phpFileInfo,
23 | $ruleSet->getClass($superTypeUsage->name())->comment()
24 | );
25 | }
26 | }
27 |
28 | return $violations;
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/src/Violation/ViolationChecker/TypeHintViolationChecker.php:
--------------------------------------------------------------------------------
1 | typeHintUsages() as $typeHintUsage) {
21 | $isClass = $ruleSet->hasClass($typeHintUsage->name());
22 |
23 | if ($isClass || $ruleSet->hasInterface($typeHintUsage->name())) {
24 | $usage = $isClass ?
25 | new ClassUsage($typeHintUsage->name(), $typeHintUsage->getLineNumber()) :
26 | new InterfaceUsage($typeHintUsage->name(), '', $typeHintUsage->getLineNumber());
27 |
28 | $comment = $isClass ?
29 | $ruleSet->getClass($typeHintUsage->name())->comment() :
30 | $ruleSet->getInterface($typeHintUsage->name())->comment();
31 |
32 | $violations[] = new Violation(
33 | $usage,
34 | $phpFileInfo,
35 | $comment
36 | );
37 | }
38 | }
39 |
40 | return $violations;
41 | }
42 | }
43 |
--------------------------------------------------------------------------------
/src/Violation/ViolationChecker/ViolationCheckerInterface.php:
--------------------------------------------------------------------------------
1 | violationChecker = $violationChecker;
32 | $this->violationFilter = $violationFilter;
33 | }
34 |
35 | /**
36 | * @param RuleSet $ruleSet
37 | * @param PhpFileInfo[] $files
38 | *
39 | * @return BaseViolation[]
40 | */
41 | public function getViolations(RuleSet $ruleSet, array $files)
42 | {
43 | $result = array();
44 | foreach ($files as $i => $file) {
45 | $unfilteredResult = $this->violationChecker->check($file, $ruleSet);
46 | foreach ($unfilteredResult as $unfilteredViolation) {
47 | if (false === $this->violationFilter->isViolationFiltered($unfilteredViolation)) {
48 | $result[] = $unfilteredViolation;
49 | }
50 | }
51 | }
52 |
53 | return $result;
54 | }
55 | }
56 |
--------------------------------------------------------------------------------
/src/Violation/ViolationFilter/ComposedViolationFilter.php:
--------------------------------------------------------------------------------
1 | violationFilters = $violationFilters;
20 | }
21 |
22 | /**
23 | * @param Violation $violation
24 | *
25 | * @return bool
26 | */
27 | public function isViolationFiltered(Violation $violation)
28 | {
29 | foreach ($this->violationFilters as $violationFilter) {
30 | if (true === $violationFilter->isViolationFiltered($violation)) {
31 | return true;
32 | }
33 | }
34 |
35 | return false;
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/Violation/ViolationFilter/MethodViolationFilter.php:
--------------------------------------------------------------------------------
1 | filterArray = $filterArray;
19 | }
20 |
21 | /**
22 | * @param string $filterConfig
23 | *
24 | * @return MethodViolationFilter
25 | */
26 | public static function fromString($filterConfig)
27 | {
28 | return new static(explode(',', $filterConfig));
29 | }
30 |
31 | /**
32 | * {@inheritdoc}
33 | */
34 | public function isViolationFiltered(Violation $violation)
35 | {
36 | $usage = $violation->getUsage();
37 | if (!$usage instanceof MethodUsage && !$usage instanceof MethodDefinition) {
38 | return false;
39 | }
40 |
41 | if ($usage instanceof MethodUsage) {
42 | $className = $usage->className();
43 | } elseif ($usage instanceof MethodDefinition) {
44 | $className = $usage->parentName();
45 | }
46 |
47 | $method = $usage->name();
48 | $usageString = sprintf('%s::%s', $className, $method);
49 |
50 | return in_array($usageString, $this->filterArray);
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Violation/ViolationFilter/ViolationFilterInterface.php:
--------------------------------------------------------------------------------
1 | phpFileInfo = $phpFileInfo;
26 |
27 | return $this;
28 | }
29 |
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public function enterNode(Node $node)
34 | {
35 | if ($node instanceof Node\Param && $node->type instanceof Node\Name) {
36 | $typeHintUsage = new TypeHintUsage($node->type->toString(), $node->getLine());
37 | $this->phpFileInfo->addTypeHintUsage($typeHintUsage);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Visitor/Usage/FindClasses.php:
--------------------------------------------------------------------------------
1 | phpFileInfo = $phpFileInfo;
26 |
27 | return $this;
28 | }
29 |
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public function enterNode(Node $node)
34 | {
35 | if ($node instanceof Node\Expr\New_ && $node->class instanceof Node\Name) {
36 | $classUsage = new ClassUsage($node->class->toString(), $node->getLine());
37 | $this->phpFileInfo->addClassUsage($classUsage);
38 | }
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/src/Visitor/Usage/FindFunctionCalls.php:
--------------------------------------------------------------------------------
1 | phpFileInfo = $phpFileInfo;
26 |
27 | return $this;
28 | }
29 |
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public function enterNode(Node $node)
34 | {
35 | if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name) {
36 | $this->phpFileInfo->addFunctionUsage(
37 | new FunctionUsage($node->name->toString(), $node->getLine())
38 | );
39 | }
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/src/Visitor/Usage/FindInterfaces.php:
--------------------------------------------------------------------------------
1 | phpFileInfo = $phpFileInfo;
26 |
27 | return $this;
28 | }
29 |
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public function enterNode(Node $node)
34 | {
35 | if ($node instanceof Node\Stmt\Class_) {
36 | if ($node->isAnonymous()) {
37 | return;
38 | }
39 |
40 | $phpFileInfo = $this->phpFileInfo;
41 | array_map(function (Node\Name $interface) use ($node, $phpFileInfo) {
42 | $interfaceUsage = new InterfaceUsage(
43 | $interface->toString(),
44 | $node->namespacedName->toString(),
45 | $node->getLine()
46 | );
47 |
48 | $phpFileInfo->addInterfaceUsage($interfaceUsage);
49 | }, $node->implements);
50 | }
51 | }
52 | }
53 |
--------------------------------------------------------------------------------
/src/Visitor/Usage/FindLanguageDeprecations.php:
--------------------------------------------------------------------------------
1 | phpFileInfo = $phpFileInfo;
26 |
27 | return $this;
28 | }
29 |
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public function enterNode(Node $node)
34 | {
35 | if ($node instanceof Node\Expr\AssignRef && $node->expr instanceof Node\Expr\New_) {
36 | $this->phpFileInfo->addDeprecatedLanguageUsage(
37 | new DeprecatedLanguageUsage(
38 | 'Assigning the return value of new by reference is now deprecated.',
39 | 'Since PHP 5.3 use normal assignment instead.',
40 | $node->getLine()
41 | )
42 | );
43 | }
44 |
45 | if ($node instanceof Node\Stmt\Class_) {
46 | $method = $node->getMethod($node->name);
47 | if ($method instanceof Node\Stmt\ClassMethod && count($node->namespacedName->parts) === 1) {
48 | $this->phpFileInfo->addDeprecatedLanguageUsage(
49 | new DeprecatedLanguageUsage(
50 | 'PHP4 constructor',
51 | 'Since PHP 7.0, use __construct() instead.',
52 | $method->getLine()
53 | )
54 | );
55 | }
56 | }
57 |
58 | if ($node instanceof Node\Arg && true === $node->byRef) {
59 | $this->phpFileInfo->addDeprecatedLanguageUsage(
60 | new DeprecatedLanguageUsage(
61 | 'call-time pass-by-reference',
62 | 'Since PHP 5.3 and removed in PHP 5.4',
63 | $node->getLine()
64 | )
65 | );
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/src/Visitor/Usage/FindMethodCalls.php:
--------------------------------------------------------------------------------
1 | phpFileInfo = $phpFileInfo;
31 |
32 | return $this;
33 | }
34 |
35 | /**
36 | * {@inheritdoc}
37 | */
38 | public function enterNode(Node $node)
39 | {
40 | if ($node instanceof Node\Stmt\ClassLike) {
41 | if (isset($node->namespacedName)) {
42 | $this->parentName = $node->namespacedName->toString();
43 | } else {
44 | $this->parentName = $node->name;
45 | }
46 | }
47 |
48 | if ($node instanceof Node\Expr\MethodCall) {
49 | // skips concat method names like $twig->{'get'.ucfirst($type)}()
50 | if ($node->name instanceof Node\Expr\BinaryOp\Concat) {
51 | return;
52 | }
53 |
54 | // skips variable methods like $definition->$method
55 | if (!is_string($node->name)) {
56 | return;
57 | }
58 |
59 | $type = $node->var->getAttribute('guessedType', null);
60 |
61 | if (null !== $type) {
62 | $methodUsage = new MethodUsage($node->name, $type, $node->getLine(), false);
63 | $this->phpFileInfo->addMethodUsage($methodUsage);
64 | }
65 | }
66 | }
67 |
68 | /**
69 | * {@inheritdoc}
70 | */
71 | public function leaveNode(Node $node)
72 | {
73 | if ($node instanceof Node\Stmt\ClassLike) {
74 | $this->parentName = null;
75 | }
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/src/Visitor/Usage/FindMethodDefinitions.php:
--------------------------------------------------------------------------------
1 | phpFileInfo = $phpFileInfo;
31 |
32 | return $this;
33 | }
34 |
35 | /**
36 | * {@inheritdoc}
37 | */
38 | public function enterNode(Node $node)
39 | {
40 | if ($node instanceof Node\Stmt\ClassLike) {
41 | if (isset($node->namespacedName)) {
42 | $this->parentName = $node->namespacedName->toString();
43 | } else {
44 | $this->parentName = $node->name;
45 | }
46 | }
47 |
48 | if ($node instanceof Node\Stmt\ClassMethod) {
49 | $methodDefinition = new MethodDefinition($node->name, $this->parentName, $node->getLine());
50 | $this->phpFileInfo->addMethodDefinition($methodDefinition);
51 | }
52 | }
53 |
54 | /**
55 | * {@inheritdoc}
56 | */
57 | public function leaveNode(Node $node)
58 | {
59 | if ($node instanceof Node\Stmt\ClassLike) {
60 | $this->parentName = null;
61 | }
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/src/Visitor/Usage/FindSuperTypes.php:
--------------------------------------------------------------------------------
1 | phpFileInfo = $phpFileInfo;
26 |
27 | return $this;
28 | }
29 |
30 | /**
31 | * {@inheritdoc}
32 | */
33 | public function enterNode(Node $node)
34 | {
35 | if ($node instanceof Node\Stmt\Class_ && $node->extends instanceof Node\Name) {
36 | if ($node->isAnonymous()) {
37 | return;
38 | }
39 |
40 | $superTypeUsage = new SuperTypeUsage(
41 | $node->extends->toString(),
42 | $node->namespacedName->toString(),
43 | $node->getLine()
44 | );
45 |
46 | $this->phpFileInfo->addSuperTypeUsage($superTypeUsage);
47 | }
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/src/Visitor/ViolationVisitorInterface.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\Configuration\Configuration', $configuration);
24 | }
25 |
26 | public function testConfiguration()
27 | {
28 | $configuration = new Configuration(
29 | 'path/to/rule_set',
30 | 'path/to/container.xml',
31 | true,
32 | 'path/to/cache/dir/',
33 | '',
34 | true,
35 | true,
36 | 'html.log',
37 | null
38 | );
39 |
40 | $this->assertEquals('path/to/rule_set', $configuration->ruleSet());
41 | $this->assertEquals('path/to/container.xml', $configuration->containerPath());
42 | $this->assertTrue($configuration->useCachedRuleSet());
43 | $this->assertEquals('path/to/cache/dir/', $configuration->ruleSetCacheDir());
44 | $this->assertEquals('', $configuration->filteredMethodCalls());
45 | $this->assertTrue($configuration->failOnDeprecation());
46 | $this->assertTrue($configuration->isVerbose());
47 | $this->assertEquals('html.log', $configuration->logHtml());
48 | $this->assertNull(null, $configuration->isSimpleOutput());
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/tests/DetectorFactoryTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\DetectorFactory', $factory);
14 | }
15 |
16 | public function testCreateDetector()
17 | {
18 | $configuration = $this->prophesize('SensioLabs\DeprecationDetector\Configuration\Configuration');
19 | $output = $this->prophesize('Symfony\Component\Console\Output\OutputInterface');
20 |
21 | $factory = new DetectorFactory();
22 |
23 | $this->assertInstanceOf(
24 | 'SensioLabs\DeprecationDetector\DeprecationDetector',
25 | $factory->create(
26 | $configuration->reveal(),
27 | $output->reveal()
28 | )
29 | );
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/tests/FileInfo/Deprecation/ClassDeprecationTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\FileInfo\Deprecation\ClassDeprecation',
15 | $classDeprecation
16 | );
17 | }
18 |
19 | public function testGetClassName()
20 | {
21 | $classDeprecation = new ClassDeprecation('className', 'comment');
22 |
23 | $this->assertSame('className', $classDeprecation->name());
24 | }
25 |
26 | public function testGetComment()
27 | {
28 | $classDeprecation = new ClassDeprecation('className', 'comment');
29 |
30 | $this->assertSame('comment', $classDeprecation->comment());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/FileInfo/Deprecation/FunctionDeprecationTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\FileInfo\Deprecation\FunctionDeprecation',
15 | $functionDeprecation
16 | );
17 | }
18 |
19 | public function testGetInterfaceName()
20 | {
21 | $functionDeprecation = new FunctionDeprecation('functionName', 'comment');
22 |
23 | $this->assertSame('functionName', $functionDeprecation->name());
24 | }
25 |
26 | public function testGetComment()
27 | {
28 | $functionDeprecation = new FunctionDeprecation('functionName', 'comment');
29 |
30 | $this->assertSame('comment', $functionDeprecation->comment());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/FileInfo/Deprecation/InterfaceDeprecationTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\FileInfo\Deprecation\InterfaceDeprecation',
15 | $interfaceDeprecation
16 | );
17 | }
18 |
19 | public function testGetInterfaceName()
20 | {
21 | $interfaceDeprecation = new InterfaceDeprecation('interfaceName', 'comment');
22 |
23 | $this->assertSame('interfaceName', $interfaceDeprecation->name());
24 | }
25 |
26 | public function testGetComment()
27 | {
28 | $interfaceDeprecation = new InterfaceDeprecation('interfaceName', 'comment');
29 |
30 | $this->assertSame('comment', $interfaceDeprecation->comment());
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/FileInfo/Deprecation/MethodDeprecationTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\FileInfo\Deprecation\MethodDeprecation',
15 | $methodDeprecation
16 | );
17 | }
18 |
19 | public function testGetClassName()
20 | {
21 | $methodDeprecation = new MethodDeprecation('className', 'methodName', 'comment');
22 |
23 | $this->assertSame('className', $methodDeprecation->parentName());
24 | }
25 |
26 | public function testGetMethodName()
27 | {
28 | $methodDeprecation = new MethodDeprecation('className', 'methodName', 'comment');
29 |
30 | $this->assertSame('methodName', $methodDeprecation->name());
31 | }
32 |
33 | public function testGetComment()
34 | {
35 | $methodDeprecation = new MethodDeprecation('className', 'methodName', 'comment');
36 |
37 | $this->assertSame('comment', $methodDeprecation->comment());
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/FileInfo/MethodDefinitionTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\FileInfo\MethodDefinition', $methodDefinition);
14 | }
15 |
16 | public function testName()
17 | {
18 | $methodDefinition = new MethodDefinition('class', 'someParentClass', 0);
19 |
20 | $this->assertSame('class', $methodDefinition->name());
21 | }
22 |
23 | public function testParentName()
24 | {
25 | $methodDefinition = new MethodDefinition('class', 'someParentClass', 0);
26 |
27 | $this->assertSame('someParentClass', $methodDefinition->parentName());
28 | }
29 |
30 | public function testGetLineNumber()
31 | {
32 | $methodDefinition = new MethodDefinition('class', 'someParentClass', 0);
33 |
34 | $this->assertSame(0, $methodDefinition->getLineNumber());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/FileInfo/Usage/ClassUsageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage', $classUsage);
14 | }
15 |
16 | public function testGetClassName()
17 | {
18 | $classUsage = new ClassUsage('name', 0);
19 |
20 | $this->assertSame('name', $classUsage->name());
21 | }
22 |
23 | public function testGetLineNumber()
24 | {
25 | $classUsage = new ClassUsage('string', 0);
26 |
27 | $this->assertSame(0, $classUsage->getLineNumber());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/FileInfo/Usage/DeprecatedLanguageUsageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\FileInfo\Usage\DeprecatedLanguageUsage', $deprecatedLanguageUsage);
14 | }
15 |
16 | public function testGetClassName()
17 | {
18 | $deprecatedLanguageUsage = new DeprecatedLanguageUsage('name', 'comment', 0);
19 |
20 | $this->assertSame('name', $deprecatedLanguageUsage->name());
21 | }
22 |
23 | public function testGetLineNumber()
24 | {
25 | $deprecatedLanguageUsage = new DeprecatedLanguageUsage('name', 'comment', 0);
26 |
27 | $this->assertSame(0, $deprecatedLanguageUsage->getLineNumber());
28 | }
29 |
30 | public function testGetComment()
31 | {
32 | $deprecatedLanguageUsage = new DeprecatedLanguageUsage('name', 'comment', 0);
33 |
34 | $this->assertSame('comment', $deprecatedLanguageUsage->comment());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/FileInfo/Usage/FunctionUsageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\FileInfo\Usage\FunctionUsage', $functionUsage);
14 | }
15 |
16 | public function testGetClassName()
17 | {
18 | $functionUsage = new FunctionUsage('name', 0);
19 |
20 | $this->assertSame('name', $functionUsage->name());
21 | }
22 |
23 | public function testGetLineNumber()
24 | {
25 | $functionUsage = new FunctionUsage('name', 0);
26 |
27 | $this->assertSame(0, $functionUsage->getLineNumber());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/FileInfo/Usage/InterfaceUsageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\FileInfo\Usage\InterfaceUsage', $interfaceUsage);
14 | }
15 |
16 | public function testGetInterfaceName()
17 | {
18 | $interfaceUsage = new InterfaceUsage('interface', 'class', 0);
19 |
20 | $this->assertSame('interface', $interfaceUsage->name());
21 | }
22 |
23 | public function testGetClassName()
24 | {
25 | $interfaceUsage = new InterfaceUsage('interface', 'class', 0);
26 |
27 | $this->assertSame('class', $interfaceUsage->className());
28 | }
29 |
30 | public function testGetLineNumber()
31 | {
32 | $interfaceUsage = new InterfaceUsage('interface', 'class', 0);
33 |
34 | $this->assertSame(0, $interfaceUsage->getLineNumber());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/FileInfo/Usage/MethodUsageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\FileInfo\Usage\MethodUsage', $methodUsage);
14 | }
15 |
16 | public function testGetMethodName()
17 | {
18 | $methodUsage = new MethodUsage('method', 'class', 0, false);
19 |
20 | $this->assertSame('method', $methodUsage->name());
21 | }
22 |
23 | public function testGetClassName()
24 | {
25 | $methodUsage = new MethodUsage('method', 'class', 0, false);
26 |
27 | $this->assertSame('class', $methodUsage->className());
28 | }
29 |
30 | public function testGetLineNumber()
31 | {
32 | $methodUsage = new MethodUsage('method', 'class', 0, false);
33 |
34 | $this->assertSame(0, $methodUsage->getLineNumber());
35 | }
36 |
37 | public function testIsStatic()
38 | {
39 | $methodUsage = new MethodUsage('method', 'class', 0, false);
40 | $this->assertSame(false, $methodUsage->isStatic());
41 |
42 | $methodUsage = new MethodUsage('method', 'class', 0, true);
43 | $this->assertSame(true, $methodUsage->isStatic());
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/tests/FileInfo/Usage/SuperTypeUsageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\FileInfo\Usage\SuperTypeUsage', $superTypeUsage);
14 | }
15 |
16 | public function testGetSuperTypeName()
17 | {
18 | $superTypeUsage = new SuperTypeUsage('superType', 'class', 0);
19 |
20 | $this->assertSame('superType', $superTypeUsage->name());
21 | }
22 |
23 | public function testGetClassName()
24 | {
25 | $superTypeUsage = new SuperTypeUsage('superType', 'class', 0);
26 |
27 | $this->assertSame('class', $superTypeUsage->className());
28 | }
29 |
30 | public function testGetLineNumber()
31 | {
32 | $superTypeUsage = new SuperTypeUsage('superType', 'class', 0);
33 |
34 | $this->assertSame(0, $superTypeUsage->getLineNumber());
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/FileInfo/Usage/TypeHintUsageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\FileInfo\Usage\TypeHintUsage', $typeHintUsage);
14 | }
15 |
16 | public function testGetTypeHintName()
17 | {
18 | $typeHintUsage = new TypeHintUsage('TypeHint', 1);
19 |
20 | $this->assertSame('TypeHint', $typeHintUsage->name());
21 | }
22 |
23 | public function testGetLineNumber()
24 | {
25 | $typeHintUsage = new TypeHintUsage('TypeHint', 1);
26 |
27 | $this->assertSame(1, $typeHintUsage->getLineNumber());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/Finder/DeprecationFinderFactoryTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('Symfony\Component\Finder\Finder', $factory->createFinder());
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/tests/Finder/ParsedPhpFileFinderTest.php:
--------------------------------------------------------------------------------
1 | prophesize('SensioLabs\DeprecationDetector\Parser\ParserInterface');
12 | $progressOutput = $this->prophesize(
13 | 'SensioLabs\DeprecationDetector\Console\Output\VerboseProgressOutput'
14 | );
15 | $finderFactory = $this->prophesize('SensioLabs\DeprecationDetector\Finder\FinderFactoryInterface');
16 |
17 | $finder = new ParsedPhpFileFinder(
18 | $parser->reveal(),
19 | $progressOutput->reveal(),
20 | $finderFactory->reveal()
21 | );
22 |
23 | $this->assertInstanceOf('SensioLabs\DeprecationDetector\Finder\ParsedPhpFileFinder', $finder);
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tests/Finder/ResultTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\Finder\Result', $result);
14 | }
15 |
16 | public function testParsedFiles()
17 | {
18 | $parsedFiles = array(
19 | $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo'),
20 | );
21 |
22 | $result = new Result($parsedFiles, array(), 10);
23 |
24 | $this->assertSame($parsedFiles, $result->parsedFiles());
25 | }
26 |
27 | public function testParserErrors()
28 | {
29 | $parserErrors = array(
30 | $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo'),
31 | );
32 |
33 | $result = new Result(array(), $parserErrors, 10);
34 |
35 | $this->assertSame($parserErrors, $result->parserErrors());
36 | }
37 |
38 | public function testFileCount()
39 | {
40 | $result = new Result(array(), array(), 10);
41 |
42 | $this->assertSame(10, $result->fileCount());
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/Finder/UsageFinderFactoryTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('Symfony\Component\Finder\Finder', $factory->createFinder());
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/tests/Parser/DeprecationParserTest.php:
--------------------------------------------------------------------------------
1 | prophesize('PhpParser\NodeTraverser')->reveal());
13 |
14 | $this->assertInstanceOf('SensioLabs\DeprecationDetector\Parser\DeprecationParser', $deprecationParser);
15 | }
16 |
17 | public function testAddDeprecationVisitor()
18 | {
19 | $visitor = $this->prophesize('SensioLabs\DeprecationDetector\Visitor\DeprecationVisitorInterface');
20 | $visitor = $visitor->reveal();
21 |
22 | $baseTraverser = $this->prophesize('PhpParser\NodeTraverser');
23 | $baseTraverser->addVisitor($visitor)->shouldBeCalled();
24 |
25 | $deprecationParser = new DeprecationParser(array(), $baseTraverser->reveal());
26 | $deprecationParser->addDeprecationVisitor($visitor);
27 | }
28 |
29 | public function testParseFile()
30 | {
31 | $phpFileInfo = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo')->reveal();
32 |
33 | $visitor = $this->prophesize('SensioLabs\DeprecationDetector\Visitor\DeprecationVisitorInterface');
34 | $visitor->setPhpFileInfo($phpFileInfo)->shouldBeCalled();
35 | $anotherVisitor = $this->prophesize('SensioLabs\DeprecationDetector\Visitor\DeprecationVisitorInterface');
36 | $anotherVisitor->setPhpFileInfo($phpFileInfo)->shouldBeCalled();
37 |
38 | $baseTraverser = $this->prophesize('PhpParser\NodeTraverser');
39 | $baseTraverser->addVisitor($visitor)->shouldBeCalled();
40 | $baseTraverser->addVisitor($anotherVisitor)->shouldBeCalled();
41 | $baseTraverser->traverse(Argument::any())->shouldBeCalled();
42 |
43 | $deprecationParser = new DeprecationParser(
44 | array($visitor->reveal(), $anotherVisitor->reveal()),
45 | $baseTraverser->reveal()
46 | );
47 | $deprecationParser->parseFile($phpFileInfo);
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/tests/RuleSet/DirectoryTraverserTest.php:
--------------------------------------------------------------------------------
1 | prophesize('SensioLabs\DeprecationDetector\Finder\ParsedPhpFileFinder');
12 |
13 | $directoryTraverser = new DirectoryTraverser($deprecationFileFinder->reveal());
14 |
15 | $this->assertInstanceOf('SensioLabs\DeprecationDetector\RuleSet\DirectoryTraverser', $directoryTraverser);
16 | }
17 |
18 | public function testTraverse()
19 | {
20 | $aPhpFileInfo = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo');
21 | $aPhpFileInfo->hasDeprecations()->willReturn(true);
22 | $aPhpFileInfo->classDeprecations()->willReturn(array());
23 | $aPhpFileInfo->methodDeprecations()->willReturn(array());
24 | $aPhpFileInfo->interfaceDeprecations()->willReturn(array());
25 |
26 | $anotherPhpFileInfo = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo');
27 | $anotherPhpFileInfo->hasDeprecations()->willReturn(false);
28 |
29 | $deprecationResult = $this->prophesize('SensioLabs\DeprecationDetector\Finder\Result');
30 | $deprecationResult->parsedFiles()->willReturn(array(
31 | $aPhpFileInfo->reveal(),
32 | $anotherPhpFileInfo->reveal(),
33 | ));
34 |
35 | $deprecationFileFinder = $this->prophesize('SensioLabs\DeprecationDetector\Finder\ParsedPhpFileFinder');
36 | $deprecationFileFinder->parsePhpFiles('some_dir')->willReturn($deprecationResult->reveal());
37 |
38 | $ruleSet = $this->prophesize('SensioLabs\DeprecationDetector\RuleSet\RuleSet');
39 | $ruleSet->merge($aPhpFileInfo->reveal())->shouldBeCalled();
40 | $ruleSet->merge($anotherPhpFileInfo->reveal())->shouldNotBeCalled();
41 |
42 | $directoryTraverser = new DirectoryTraverser($deprecationFileFinder->reveal());
43 | $directoryTraverser->traverse('some_dir', $ruleSet->reveal());
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/tests/RuleSet/Loader/Composer/ComposerFactoryTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\ComposerFactory', $factory);
15 | }
16 |
17 | public function testFromLockThrowsComposerFileDoesNotExistException()
18 | {
19 | $factory = new ComposerFactory();
20 |
21 | $this->setExpectedException(
22 | 'SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\Exception\ComposerFileDoesNotExistsException',
23 | 'composer.lock file "path/to/not/existing/composer.lock" does not exist.'
24 | );
25 | $factory->fromLock('path/to/not/existing/composer.lock');
26 | }
27 |
28 | public function testFromLockThrowsComposerFileIsInvalidException()
29 | {
30 | $factory = new ComposerFactory();
31 |
32 | $root = vfsStream::setup('root');
33 | $file = vfsStream::newFile('composer.lock');
34 | $file->setContent('invalid;lock_file;');
35 | $root->addChild($file);
36 |
37 | $this->setExpectedException(
38 | 'SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\Exception\ComposerFileIsInvalidException',
39 | 'composer.lock file "vfs://root/composer.lock" is invalid.'
40 | );
41 | $factory->fromLock(vfsStream::url('root/composer.lock'));
42 | }
43 |
44 | public function testFromLockReturnsComposerObject()
45 | {
46 | $factory = new ComposerFactory();
47 |
48 | $root = vfsStream::setup('root');
49 | $file = vfsStream::newFile('composer.lock');
50 | $file->setContent(
51 | '{"_readme": [],"hash": "ac82fae1f7095370dc4c7299aa637a30","content-hash": "3faf23edaf51060bfe1830506104ec83","packages": [{"name": "vendor/lib","version": "v2.7.6"}], "packages-dev": [{"name": "vendor/devlib","version": "v0.0.6"}]}'
52 | );
53 | $root->addChild($file);
54 | $this->assertInstanceOf(
55 | 'SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\Composer',
56 | $composer = $factory->fromLock(vfsStream::url('root/composer.lock'))
57 | );
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/tests/RuleSet/Loader/Composer/ComposerTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\Composer', $composer);
14 | }
15 |
16 | public function testGetPackagesWithDevPackages()
17 | {
18 | $aPackage = $this->prophesize('SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\Package')->reveal();
19 | $anotherPackage = $this->prophesize('SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\Package')->reveal();
20 |
21 | $composer = new Composer(array($aPackage), array($anotherPackage), true);
22 | $this->assertEquals(array($aPackage, $anotherPackage), $composer->getPackages());
23 | }
24 |
25 | public function testGetPackagesWithoutDevPackages()
26 | {
27 | $aPackage = $this->prophesize('SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\Package')->reveal();
28 | $anotherPackage = $this->prophesize('SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\Package')->reveal();
29 |
30 | $composer = new Composer(array($aPackage), array($anotherPackage), false);
31 | $this->assertEquals(array($aPackage), $composer->getPackages());
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tests/RuleSet/Loader/Composer/Exception/ComposerExceptionTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\Exception\ComposerException', $exception);
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/tests/RuleSet/Loader/Composer/Exception/ComposerFileDoesNotExistsExceptionTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\Exception\ComposerException', $exception);
13 | $this->assertEquals('composer.lock file "path/to/lock" does not exist.', $exception->getMessage());
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/tests/RuleSet/Loader/Composer/Exception/ComposerFileIsInvalidExceptionTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\Exception\ComposerException', $exception);
13 | $this->assertEquals('composer.lock file "path/to/lock" is invalid.', $exception->getMessage());
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/tests/RuleSet/Loader/Composer/PackageTest.php:
--------------------------------------------------------------------------------
1 | 'vendor/lib',
13 | 'version' => '1.0.0',
14 | ));
15 |
16 | $this->assertInstanceOf('SensioLabs\DeprecationDetector\RuleSet\Loader\Composer\Package', $package);
17 | }
18 |
19 | public function testGeneratePackageKey()
20 | {
21 | $package = Package::fromArray(array(
22 | 'name' => 'vendor/lib',
23 | 'version' => '1.0.0',
24 | ));
25 |
26 | $this->assertEquals('vendor_lib_1.0.0', $package->generatePackageKey());
27 | }
28 |
29 | public function testGetPackagePath()
30 | {
31 | $package = Package::fromArray(array(
32 | 'name' => 'vendor/lib',
33 | 'version' => '1.0.0',
34 | ));
35 |
36 | $this->assertEquals('vendor/vendor/lib', $package->getPackagePath('vendor/'));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tests/RuleSet/Loader/CouldNotLoadRuleSetExceptionTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\RuleSet\Loader\CouldNotLoadRuleSetException',
15 | $exception
16 | );
17 | }
18 |
19 | public function testMessage()
20 | {
21 | $exception = new CouldNotLoadRuleSetException('an exception message');
22 |
23 | $this->assertSame('an exception message', $exception->getMessage());
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/tests/RuleSet/Loader/FileLoaderTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\RuleSet\Loader\FileLoader', $loader);
14 | }
15 |
16 | public function testLoadingNotExistingFileThrowsAnException()
17 | {
18 | $loader = new FileLoader();
19 |
20 | $this->setExpectedException(
21 | 'SensioLabs\DeprecationDetector\RuleSet\Loader\CouldNotLoadRuleSetException',
22 | 'Ruleset "no_such.file" does not exist, aborting.'
23 | );
24 | $loader->loadRuleSet('no_such.file');
25 | }
26 |
27 | public function testLoadRuleSetThrowsExceptionIfCachedIsNotAnInstanceOfRuleset()
28 | {
29 | //@TODO: file_get_contents is untestable
30 | $this->markTestSkipped();
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/tests/TypeGuessing/ConstructorResolver/Visitor/ConstructorResolverVisitorTest.php:
--------------------------------------------------------------------------------
1 | prophesize('SensioLabs\DeprecationDetector\TypeGuessing\ConstructorResolver\ConstructorResolver');
15 | $visitor = new ConstructorResolverVisitor($resolver->reveal());
16 |
17 | $this->assertInstanceOf(
18 | 'SensioLabs\DeprecationDetector\TypeGuessing\ConstructorResolver\Visitor\ConstructorResolverVisitor',
19 | $visitor
20 | );
21 | }
22 |
23 | public function testComputesClassNodes()
24 | {
25 | $node = new Class_('SomeClass');
26 | $resolver = $this
27 | ->prophesize('SensioLabs\DeprecationDetector\TypeGuessing\ConstructorResolver\ConstructorResolver');
28 | $resolver->resolveConstructor($node)->shouldBeCalled();
29 | $visitor = new ConstructorResolverVisitor($resolver->reveal());
30 |
31 | $visitor->enterNode($node);
32 | }
33 |
34 | public function testDoesNotComputeOtherNodes()
35 | {
36 | $node = new Function_('someFunction');
37 | $resolver = $this
38 | ->prophesize('SensioLabs\DeprecationDetector\TypeGuessing\ConstructorResolver\ConstructorResolver');
39 | $resolver->resolveConstructor($node)->shouldNotBeCalled();
40 | $visitor = new ConstructorResolverVisitor($resolver->reveal());
41 |
42 | $visitor->enterNode($node);
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/TypeGuessing/SymbolTable/ComposedResolverTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\ComposedResolver', $resolver);
15 | }
16 |
17 | public function testCallsEveryResolverOnce()
18 | {
19 | $composedResolver = new ComposedResolver();
20 |
21 | $someResolver = $this
22 | ->prophesize('SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\Resolver\ResolverInterface');
23 | $someResolver->resolveVariableType(Argument::any())->shouldBeCalled();
24 |
25 | $someOtherResolver = $this
26 | ->prophesize('SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\Resolver\ResolverInterface');
27 | $someOtherResolver->resolveVariableType(Argument::any())->shouldBeCalled();
28 |
29 | $node = $this->prophesize('PhpParser\Node');
30 |
31 | $composedResolver->addResolver($someResolver->reveal());
32 | $composedResolver->addResolver($someOtherResolver->reveal());
33 | $composedResolver->resolveVariableType($node->reveal());
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/TypeGuessing/SymbolTable/Resolver/ArgumentResolverTest.php:
--------------------------------------------------------------------------------
1 | prophesize('SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\SymbolTable');
14 | $resolver = new ArgumentResolver($table->reveal());
15 |
16 | $this->assertInstanceOf(
17 | 'SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\Resolver\ArgumentResolver',
18 | $resolver
19 | );
20 | }
21 |
22 | public function testResolveTypedArgument()
23 | {
24 | $table = $this->prophesize('SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\SymbolTable');
25 | $table->setSymbol('var', 'SomeClass')->shouldBeCalled();
26 | $resolver = new ArgumentResolver($table->reveal());
27 |
28 | $param = new Param('var', null, new Name('SomeClass'));
29 | $resolver->resolveVariableType($param);
30 | }
31 |
32 | public function testSkipsUntypedArgument()
33 | {
34 | $table = $this->prophesize('SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\SymbolTable');
35 | $table->setSymbol('var', 'SomeClass')->shouldNotBeCalled();
36 | $resolver = new ArgumentResolver($table->reveal());
37 |
38 | $param = new Param('var');
39 | $resolver->resolveVariableType($param);
40 | }
41 | }
42 |
--------------------------------------------------------------------------------
/tests/TypeGuessing/SymbolTable/Resolver/ReattachStateToPropertyTest.php:
--------------------------------------------------------------------------------
1 | prophesize('SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\SymbolTable');
15 | $resolver = new ReattachStateToProperty($table->reveal());
16 |
17 | $this->assertInstanceOf(
18 | 'SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\Resolver\ReattachStateToProperty',
19 | $resolver
20 | );
21 | }
22 |
23 | public function testGuessedTypeIsReattached()
24 | {
25 | $table = $this->prophesize('SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\SymbolTable');
26 | $table->lookUpClassProperty('prop')->willReturn(new Symbol('prop', 'SomeClass'));
27 |
28 | $resolver = new ReattachStateToProperty($table->reveal());
29 |
30 | $node = new PropertyFetch(new Variable('this'), 'prop');
31 |
32 | $resolver->resolveVariableType($node);
33 | $this->assertSame('SomeClass', $node->getAttribute('guessedType'));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/TypeGuessing/SymbolTable/Resolver/ReattachStateToVariableTest.php:
--------------------------------------------------------------------------------
1 | prophesize('SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\SymbolTable');
14 | $resolver = new ReattachStateToVariable($table->reveal());
15 |
16 | $this->assertInstanceOf(
17 | 'SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\Resolver\ReattachStateToVariable',
18 | $resolver
19 | );
20 | }
21 |
22 | public function testGuessedTypeIsReattached()
23 | {
24 | $table = $this->prophesize('SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\SymbolTable');
25 | $table->lookUp('var')->willReturn(new Symbol('var', 'SomeClass'));
26 | $resolver = new ReattachStateToVariable($table->reveal());
27 |
28 | $node = new Variable('var');
29 |
30 | $resolver->resolveVariableType($node);
31 | $this->assertSame('SomeClass', $node->getAttribute('guessedType'));
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/tests/TypeGuessing/SymbolTable/SymbolTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\Symbol', $symbol);
14 | }
15 |
16 | public function testGetSymbol()
17 | {
18 | $symbol = new Symbol('var', 'class');
19 |
20 | $this->assertSame('var', $symbol->symbol());
21 | }
22 |
23 | public function testGetType()
24 | {
25 | $symbol = new Symbol('var', 'class');
26 |
27 | $this->assertSame('class', $symbol->type());
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/tests/TypeGuessing/SymbolTable/TableScopeTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\TypeGuessing\SymbolTable\TableScope', $scope);
15 | }
16 |
17 | public function testScope()
18 | {
19 | $scope = new TableScope(TableScope::CLASS_LIKE_SCOPE);
20 |
21 | $this->assertSame(TableScope::CLASS_LIKE_SCOPE, $scope->scope());
22 | }
23 |
24 | public function testFindSymbolReturnsNull()
25 | {
26 | $scope = new TableScope(TableScope::CLASS_LIKE_SCOPE);
27 |
28 | $this->assertNull($scope->findSymbol('var'));
29 | }
30 |
31 | public function testSetAndFindSymbol()
32 | {
33 | $scope = new TableScope(TableScope::CLASS_LIKE_SCOPE);
34 | $scope->setSymbol($result = new Symbol('var', 'class'));
35 |
36 | $this->assertSame($result, $scope->findSymbol('var'));
37 | }
38 | }
39 |
--------------------------------------------------------------------------------
/tests/TypeGuessing/Symfony/ContainerReaderTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\TypeGuessing\Symfony\ContainerReader', $container);
14 | }
15 |
16 | public function testWithoutLoading()
17 | {
18 | $container = new ContainerReader();
19 |
20 | $this->assertNull($container->has('service.unit'));
21 | $this->assertNull($container->get('service.unit'));
22 | }
23 |
24 | public function testLoadInvalidPath()
25 | {
26 | $container = new ContainerReader();
27 | $loaded = $container->loadContainer(__DIR__.'/invalidPath.xml');
28 |
29 | $this->assertFalse($loaded);
30 | }
31 |
32 | public function testLoadInvalidDump()
33 | {
34 | $container = new ContainerReader();
35 | $loaded = $container->loadContainer(__FILE__);
36 |
37 | $this->assertFalse($loaded);
38 | }
39 |
40 | public function testLoadValidDump()
41 | {
42 | $container = new ContainerReader();
43 | $loaded = $container->loadContainer(__DIR__.'/containerDump.xml');
44 |
45 | $this->assertTrue($loaded);
46 |
47 | $this->assertTrue($container->has('service.unit'));
48 | $this->assertFalse($container->has('service.invalid'));
49 |
50 | $this->assertEquals('UnitTest\Class', $container->get('service.unit'));
51 | $this->assertNull($container->get('service.unit2'));
52 | }
53 |
54 | /**
55 | * @expectedException \BadMethodCallException
56 | */
57 | public function testInvalidCall()
58 | {
59 | $container = new ContainerReader();
60 | $container->loadContainer(__DIR__.'/containerDump.xml');
61 |
62 | $container->getDefinition('service.unit');
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/tests/TypeGuessing/Symfony/containerDump.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/tests/Violation/Renderer/Html/RendererFactoryTest.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | class RendererFactoryTest extends PHPUnit_Framework_TestCase
16 | {
17 | public function testCreateRenderer()
18 | {
19 | $factory = new RendererFactory(new MessageHelper(), new Filesystem());
20 |
21 | $this->assertInstanceOf(
22 | 'SensioLabs\DeprecationDetector\Violation\Renderer\Html\Renderer',
23 | $factory->createHtmlOutputRenderer('./output.html')
24 | );
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/tests/Violation/Renderer/Html/RendererTest.php:
--------------------------------------------------------------------------------
1 |
14 | */
15 | class RendererTest extends PHPUnit_Framework_TestCase
16 | {
17 | /**
18 | * @var vfsStreamDirectory
19 | */
20 | private $root;
21 |
22 | /**
23 | * set up test environment.
24 | */
25 | public function setUp()
26 | {
27 | $this->root = vfsStream::setup('exampleDir');
28 | }
29 |
30 | public function testRenderViolations()
31 | {
32 | $fileSystem = $this->prophesize('Symfony\Component\Filesystem\Filesystem');
33 | $fileSystem->mkdir('exampleDir');
34 |
35 | $fileInfo = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo');
36 | $fileInfo->getPathname()->willReturn('just/a/path');
37 |
38 | $violation = $this->prophesize('SensioLabs\DeprecationDetector\Violation\Violation');
39 | $violation->getFile()->willReturn($fileInfo->reveal());
40 | $violation->getLine()->willReturn('12');
41 | $violation->getComment()->willReturn('Just a comment');
42 |
43 | $messageHelper = $this->prophesize('SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\MessageHelper');
44 | $messageHelper->getViolationMessage($violation->reveal())->willReturn('testMethod');
45 |
46 | $renderer = new Renderer(
47 | $messageHelper->reveal(),
48 | $fileSystem->reveal(),
49 | vfsStream::url('exampleDir/output.html')
50 | );
51 |
52 | $renderer->renderViolations(array($violation->reveal()), array());
53 |
54 | $this->assertFileExists(vfsStream::url('exampleDir/output.html'));
55 |
56 | $fileContent = file_get_contents(vfsStream::url('exampleDir/output.html'));
57 |
58 | $this->assertContains('testMethod', $fileContent);
59 | $this->assertContains('12', $fileContent);
60 | $this->assertContains('Just a comment', $fileContent);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/tests/Violation/Renderer/MessageHelper/Message/BaseViolationMessageImplementation.php:
--------------------------------------------------------------------------------
1 | prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
10 | $baseViolationMessage
11 | = new BaseViolationMessageImplementation('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
12 |
13 | $this->assertTrue($baseViolationMessage->supports($usage->reveal()));
14 |
15 | $usage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\InterfaceUsage');
16 | $this->assertFalse($baseViolationMessage->supports($usage->reveal()));
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/tests/Violation/Renderer/MessageHelper/Message/ClassViolationMessageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\ClassViolationMessage',
15 | $message
16 | );
17 | }
18 |
19 | public function testMessageWithSupportedUsage()
20 | {
21 | $classUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
22 | $classUsage->name()->willReturn('SomeClass');
23 | $message = new ClassViolationMessage('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
24 |
25 | $this->assertSame('Using deprecated class SomeClass', $message->message($classUsage->reveal()));
26 | }
27 |
28 | public function testMessageWithUnsupportedMessage()
29 | {
30 | $interfaceUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\InterfaceUsage');
31 | $interfaceUsage->name()->willReturn('SomeClass');
32 | $message = new ClassViolationMessage('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
33 |
34 | $this->assertSame('', $message->message($interfaceUsage->reveal()));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/Violation/Renderer/MessageHelper/Message/FunctionViolationMessageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\FunctionViolationMessage',
15 | $message
16 | );
17 | }
18 |
19 | public function testMessageWithSupportedUsage()
20 | {
21 | $functionUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\FunctionUsage');
22 | $functionUsage->name()->willReturn('someFunction');
23 | $message = new FunctionViolationMessage('SensioLabs\DeprecationDetector\FileInfo\Usage\FunctionUsage');
24 |
25 | $this->assertSame('Using deprecated function someFunction()', $message->message($functionUsage->reveal()));
26 | }
27 |
28 | public function testMessageWithUnsupportedMessage()
29 | {
30 | $interfaceUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\InterfaceUsage');
31 | $interfaceUsage->name()->willReturn('SomeClass');
32 | $message = new FunctionViolationMessage('SensioLabs\DeprecationDetector\FileInfo\Usage\FunctionUsage');
33 |
34 | $this->assertSame('', $message->message($interfaceUsage->reveal()));
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/tests/Violation/Renderer/MessageHelper/Message/InterfaceViolationMessageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\InterfaceViolationMessage',
15 | $message
16 | );
17 | }
18 |
19 | public function testMessageWithSupportedUsage()
20 | {
21 | $interfaceUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\InterfaceUsage');
22 | $interfaceUsage->name()->willReturn('SomeInterface');
23 | $interfaceUsage->className()->willReturn(null);
24 | $message = new InterfaceViolationMessage('SensioLabs\DeprecationDetector\FileInfo\Usage\InterfaceUsage');
25 |
26 | $this->assertSame(
27 | 'Using deprecated interface SomeInterface',
28 | $message->message($interfaceUsage->reveal())
29 | );
30 |
31 | $interfaceUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\InterfaceUsage');
32 | $interfaceUsage->name()->willReturn('SomeInterface');
33 | $interfaceUsage->className()->willReturn('SomeClass');
34 |
35 | $this->assertSame(
36 | 'Using deprecated interface SomeInterface by class SomeClass',
37 | $message->message($interfaceUsage->reveal())
38 | );
39 | }
40 |
41 | public function testMessageWithUnsupportedMessage()
42 | {
43 | $classUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
44 | $message = new InterfaceViolationMessage('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
45 |
46 | $this->assertSame('', $message->message($classUsage->reveal()));
47 | }
48 | }
49 |
--------------------------------------------------------------------------------
/tests/Violation/Renderer/MessageHelper/Message/LanguageDeprecationMessageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\LanguageDeprecationMessage',
15 | $message
16 | );
17 | }
18 |
19 | public function testMessageWithSupportedUsage()
20 | {
21 | $deprecatedLanguageUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\DeprecatedLanguageUsage');
22 | $deprecatedLanguageUsage->name()->willReturn('PHP4 constructor');
23 | $message = new LanguageDeprecationMessage('SensioLabs\DeprecationDetector\FileInfo\Usage\DeprecatedLanguageUsage');
24 |
25 | $this->assertSame('Using deprecated language feature PHP4 constructor', $message->message($deprecatedLanguageUsage->reveal()));
26 | }
27 |
28 | public function testMessageWithUnsupportedMessage()
29 | {
30 | $interfaceUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\InterfaceUsage');
31 | $message = new LanguageDeprecationMessage('SensioLabs\DeprecationDetector\FileInfo\Usage\DeprecatedLanguageUsage');
32 |
33 | $this->assertSame('', $message->message($interfaceUsage->reveal()));
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/tests/Violation/Renderer/MessageHelper/Message/MethodDefinitionViolationMessageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\MethodDefinitionViolationMessage',
15 | $message
16 | );
17 | }
18 |
19 | public function testMessageWithSupportedUsage()
20 | {
21 | $methodDefinition = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\MethodDefinition');
22 | $methodDefinition->parentName()->willReturn('SomeClass');
23 | $methodDefinition->name()->willReturn('someMethod');
24 | $message = new MethodDefinitionViolationMessage('SensioLabs\DeprecationDetector\FileInfo\MethodDefinition');
25 |
26 | $this->assertSame(
27 | 'Overriding deprecated method SomeClass->someMethod()',
28 | $message->message($methodDefinition->reveal())
29 | );
30 | }
31 |
32 | public function testMessageWithUnsupportedMessage()
33 | {
34 | $classUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
35 | $message = new MethodDefinitionViolationMessage('SensioLabs\DeprecationDetector\FileInfo\MethodDefinition');
36 |
37 | $this->assertSame('', $message->message($classUsage->reveal()));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/Violation/Renderer/MessageHelper/Message/MethodViolationMessageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\MethodViolationMessage',
15 | $message
16 | );
17 | }
18 |
19 | public function testMessageWithSupportedUsage()
20 | {
21 | $methodUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\MethodUsage');
22 | $methodUsage->name()->willReturn('someMethod');
23 | $methodUsage->className()->willReturn('SomeClass');
24 | $methodUsage->isStatic()->willReturn(false);
25 | $message = new MethodViolationMessage('SensioLabs\DeprecationDetector\FileInfo\Usage\MethodUsage');
26 |
27 | $this->assertSame(
28 | 'Calling deprecated method SomeClass->someMethod()',
29 | $message->message($methodUsage->reveal())
30 | );
31 |
32 | $methodUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\MethodUsage');
33 | $methodUsage->name()->willReturn('someMethod');
34 | $methodUsage->className()->willReturn('SomeClass');
35 | $methodUsage->isStatic()->willReturn(true);
36 |
37 | $this->assertSame(
38 | 'Calling deprecated static method SomeClass::someMethod()',
39 | $message->message($methodUsage->reveal())
40 | );
41 | }
42 |
43 | public function testMessageWithUnsupportedMessage()
44 | {
45 | $interfaceUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\InterfaceUsage');
46 | $message = new MethodViolationMessage('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
47 |
48 | $this->assertSame('', $message->message($interfaceUsage->reveal()));
49 | }
50 | }
51 |
--------------------------------------------------------------------------------
/tests/Violation/Renderer/MessageHelper/Message/SuperTypeViolationMessageTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\SuperTypeViolationMessage',
15 | $message
16 | );
17 | }
18 |
19 | public function testMessageWithSupportedUsage()
20 | {
21 | $superTypeUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\SuperTypeUsage');
22 | $superTypeUsage->name()->willReturn('SomeSuperType');
23 | $superTypeUsage->className()->willReturn('SomeClass');
24 | $message = new SuperTypeViolationMessage('SensioLabs\DeprecationDetector\FileInfo\Usage\SuperTypeUsage');
25 |
26 | $this->assertSame(
27 | 'Extending deprecated class SomeSuperType by class SomeClass',
28 | $message->message($superTypeUsage->reveal())
29 | );
30 | }
31 |
32 | public function testMessageWithUnsupportedMessage()
33 | {
34 | $classUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
35 | $message = new SuperTypeViolationMessage('SensioLabs\DeprecationDetector\FileInfo\Usage\SuperTypeUsage');
36 |
37 | $this->assertSame('', $message->message($classUsage->reveal()));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/tests/Violation/Renderer/MessageHelper/MessageHelperTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf(
14 | 'SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\MessageHelper',
15 | $messageHelper
16 | );
17 | }
18 |
19 | public function testAddViolationMessageAndGetViolationMessage()
20 | {
21 | $usage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\UsageInterface');
22 |
23 | $violation = $this->prophesize('SensioLabs\DeprecationDetector\Violation\Violation');
24 | $violation->getUsage()->willReturn($usage->reveal());
25 | $violation = $violation->reveal();
26 |
27 | $violationMessage = $this->prophesize(
28 | 'SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\BaseViolationMessage'
29 | );
30 | $violationMessage->supports($usage)->willReturn(false);
31 | $violationMessage->message($usage)->shouldNotBeCalled();
32 |
33 | $anotherViolationMessage = $this->prophesize(
34 | 'SensioLabs\DeprecationDetector\Violation\Renderer\MessageHelper\Message\BaseViolationMessage'
35 | );
36 | $anotherViolationMessage->supports($usage)->willReturn(true);
37 | $anotherViolationMessage->message($usage)->willReturn('some deprecated things used');
38 |
39 | $messageHelper = new MessageHelper();
40 | $messageHelper->addViolationMessage($violationMessage->reveal());
41 | $messageHelper->addViolationMessage($anotherViolationMessage->reveal());
42 |
43 | $this->assertSame('some deprecated things used', $messageHelper->getViolationMessage($violation));
44 | }
45 |
46 | public function testFallbackMessage()
47 | {
48 | $usage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
49 | $usage->name()->willReturn('SomeClass');
50 |
51 | $violation = $this->prophesize('SensioLabs\DeprecationDetector\Violation\Violation');
52 | $violation->getUsage()->willReturn($usage->reveal());
53 |
54 | $messageHelper = new MessageHelper();
55 | $this->assertRegExp(
56 | '#Deprecated P[0-9]+ SomeClass#',
57 | $messageHelper->getViolationMessage($violation->reveal())
58 | );
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/tests/Violation/ViolationChecker/ClassViolationCheckerTest.php:
--------------------------------------------------------------------------------
1 | prophesize('SensioLabs\DeprecationDetector\RuleSet\RuleSet');
13 | $checker = new ClassViolationChecker($ruleSet->reveal());
14 |
15 | $this->assertInstanceOf(
16 | 'SensioLabs\DeprecationDetector\Violation\ViolationChecker\ClassViolationChecker',
17 | $checker
18 | );
19 | }
20 |
21 | public function testCheck()
22 | {
23 | $classUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
24 | $classUsage->name()->willReturn('class');
25 |
26 | $deprecatedClassUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\ClassUsage');
27 | $deprecatedClassUsage->name()->willReturn('deprecatedClass');
28 | $deprecatedClassUsage->getLineNumber()->willReturn(10);
29 |
30 | $classUsage = $classUsage->reveal();
31 | $deprecatedClassUsage = $deprecatedClassUsage->reveal();
32 |
33 | $ruleSet = $this->prophesize('SensioLabs\DeprecationDetector\RuleSet\RuleSet');
34 | $collection = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo');
35 | $collection->classUsages()->willReturn(array(
36 | $classUsage,
37 | $deprecatedClassUsage,
38 | ));
39 | $collection = $collection->reveal();
40 |
41 | $ruleSet->hasClass('class')->willReturn(false);
42 | $ruleSet->hasClass('deprecatedClass')->willReturn(true);
43 |
44 | $deprecationComment = 'comment';
45 | $classDeprecation = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Deprecation\ClassDeprecation');
46 | $classDeprecation->comment()->willReturn($deprecationComment);
47 |
48 | $ruleSet->getClass('deprecatedClass')->willReturn($classDeprecation->reveal());
49 |
50 | $checker = new ClassViolationChecker();
51 |
52 | $this->assertEquals(array(
53 | new Violation($deprecatedClassUsage, $collection, $deprecationComment),
54 | ), $checker->check($collection, $ruleSet->reveal()));
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/tests/Violation/ViolationChecker/SuperTypeViolationCheckerTest.php:
--------------------------------------------------------------------------------
1 | prophesize('SensioLabs\DeprecationDetector\RuleSet\RuleSet');
13 | $checker = new SuperTypeViolationChecker($ruleSet->reveal());
14 |
15 | $this->assertInstanceOf(
16 | 'SensioLabs\DeprecationDetector\Violation\ViolationChecker\SuperTypeViolationChecker',
17 | $checker
18 | );
19 | }
20 |
21 | public function testCheck()
22 | {
23 | $superTypeUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\SuperTypeUsage');
24 | $superTypeUsage->name()->willReturn('class');
25 |
26 | $deprecatedSuperTypeUsage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\SuperTypeUsage');
27 | $deprecatedSuperTypeUsage->name()->willReturn('deprecatedClass');
28 | $deprecatedSuperTypeUsage->className()->willReturn('someClass');
29 | $deprecatedSuperTypeUsage->getLineNumber()->willReturn(10);
30 |
31 | $superTypeUsage = $superTypeUsage->reveal();
32 | $deprecatedSuperTypeUsage = $deprecatedSuperTypeUsage->reveal();
33 |
34 | $ruleSet = $this->prophesize('SensioLabs\DeprecationDetector\RuleSet\RuleSet');
35 | $collection = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo');
36 | $collection->superTypeUsages()->willReturn(array(
37 | $superTypeUsage,
38 | $deprecatedSuperTypeUsage,
39 | ));
40 | $collection = $collection->reveal();
41 |
42 | $ruleSet->hasClass('class')->willReturn(false);
43 | $ruleSet->hasClass('deprecatedClass')->willReturn(true);
44 |
45 | $deprecationComment = 'comment';
46 | $classDeprecation = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Deprecation\ClassDeprecation');
47 | $classDeprecation->comment()->willReturn($deprecationComment);
48 |
49 | $ruleSet->getClass('deprecatedClass')->willReturn($classDeprecation->reveal());
50 |
51 | $checker = new SuperTypeViolationChecker();
52 |
53 | $this->assertEquals(array(
54 | new Violation($deprecatedSuperTypeUsage, $collection, $deprecationComment),
55 | ), $checker->check($collection, $ruleSet->reveal()));
56 | }
57 | }
58 |
--------------------------------------------------------------------------------
/tests/Violation/ViolationDetectorTest.php:
--------------------------------------------------------------------------------
1 | prophesize(
12 | 'SensioLabs\DeprecationDetector\Violation\ViolationChecker\ViolationCheckerInterface'
13 | );
14 | $violationFilter = $this->prophesize(
15 | 'SensioLabs\DeprecationDetector\Violation\ViolationFilter\ViolationFilterInterface'
16 | );
17 | $violationDetector = new ViolationDetector(
18 | $violationChecker->reveal(),
19 | $violationFilter->reveal()
20 | );
21 |
22 | $this->assertInstanceOf('SensioLabs\DeprecationDetector\Violation\ViolationDetector', $violationDetector);
23 | }
24 |
25 | public function testGetViolations()
26 | {
27 | $violation = $this->prophesize('SensioLabs\DeprecationDetector\Violation\Violation')->reveal();
28 | $filteredViolation = $this->prophesize('SensioLabs\DeprecationDetector\Violation\Violation')->reveal();
29 |
30 | $expected = array($violation);
31 | $phpFileInfo = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo')->reveal();
32 | $ruleSet = $this->prophesize('SensioLabs\DeprecationDetector\RuleSet\RuleSet')->reveal();
33 |
34 | $violationChecker = $this->prophesize(
35 | 'SensioLabs\DeprecationDetector\Violation\ViolationChecker\ViolationCheckerInterface'
36 | );
37 |
38 | $violationChecker
39 | ->check($phpFileInfo, $ruleSet)
40 | ->willReturn(array($violation, $filteredViolation))
41 | ->shouldBeCalled();
42 |
43 | $violationFilter = $this->prophesize(
44 | 'SensioLabs\DeprecationDetector\Violation\ViolationFilter\ViolationFilterInterface'
45 | );
46 | $violationFilter->isViolationFiltered($violation)->willReturn(false)->shouldBeCalled();
47 | $violationFilter->isViolationFiltered($filteredViolation)->willReturn(true)->shouldBeCalled();
48 |
49 | $violationDetector = new ViolationDetector(
50 | $violationChecker->reveal(),
51 | $violationFilter->reveal()
52 | );
53 |
54 | $this->assertEquals(
55 | $expected,
56 | $violationDetector->getViolations($ruleSet, array($phpFileInfo))
57 | );
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/tests/Violation/ViolationFilter/MethodViolationFilterTest.php:
--------------------------------------------------------------------------------
1 | methodViolationFilter = new MethodViolationFilter($this->filterList);
20 | }
21 |
22 | public function tearDown()
23 | {
24 | parent::tearDown();
25 | $this->methodViolationFilter = null;
26 | }
27 |
28 | /**
29 | * @dataProvider getFilteredViolations
30 | */
31 | public function testFilterViolations($checkedClass, $checkedName, $expectedToBeFiltered)
32 | {
33 | $usage = $this->prophesize('\SensioLabs\DeprecationDetector\FileInfo\Usage\MethodUsage');
34 | $usage->className()->willReturn($checkedClass);
35 | $usage->name()->willReturn($checkedName);
36 | $violation = $this->prophesize('\SensioLabs\DeprecationDetector\Violation\Violation');
37 | $violation->getUsage()->willReturn($usage->reveal());
38 | $filtered = $this->methodViolationFilter->isViolationFiltered($violation->reveal());
39 | $this->assertEquals($expectedToBeFiltered, $filtered);
40 | }
41 |
42 | /**
43 | * @dataProvider getFilteredViolations
44 | */
45 | public function testNotFilteringNonMethodUsages($checkedClass, $checkedName, $expectedToBeFiltered)
46 | {
47 | $usage = $this->prophesize('\SensioLabs\DeprecationDetector\FileInfo\Usage\UsageInterface');
48 | $violation = $this->prophesize('\SensioLabs\DeprecationDetector\Violation\Violation');
49 | $violation->getUsage()->willReturn($usage->reveal());
50 | $filtered = $this->methodViolationFilter->isViolationFiltered($violation->reveal());
51 | $this->assertFalse($filtered);
52 | }
53 |
54 | public function getFilteredViolations()
55 | {
56 | return array(
57 | array('Checked', 'method', true),
58 | array('\\Foo\\Checked', 'method2', true),
59 | array('Checkedd', 'method', false),
60 | array('\\Foo\\Checked\\Bar', 'method2', false),
61 |
62 | );
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/tests/Violation/ViolationTest.php:
--------------------------------------------------------------------------------
1 | prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\UsageInterface');
12 | $file = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo');
13 |
14 | $violation = new Violation($usage->reveal(), $file->reveal(), 'comment');
15 |
16 | $this->assertInstanceOf('SensioLabs\DeprecationDetector\Violation\Violation', $violation);
17 | }
18 |
19 | public function testGetters()
20 | {
21 | $usage = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\Usage\UsageInterface');
22 | $usage->getLineNumber()->willReturn(10);
23 | $usage = $usage->reveal();
24 | $file = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo');
25 | $file = $file->reveal();
26 |
27 | $violation = new Violation($usage, $file, 'comment');
28 |
29 | $this->assertEquals(10, $violation->getLine());
30 | $this->assertEquals($usage, $violation->getUsage());
31 | $this->assertEquals($file, $violation->getFile());
32 | $this->assertEquals('comment', $violation->getComment());
33 | }
34 | }
35 |
--------------------------------------------------------------------------------
/tests/Visitor/Usage/FindClassesTest.php:
--------------------------------------------------------------------------------
1 | prophesize('Symfony\Component\Finder\SplFileInfo');
24 | $phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor(
25 | $file = PhpFileInfo::create($splFileInfo->reveal()),
26 | $source,
27 | new FindClasses()
28 | );
29 |
30 | $this->assertEquals(
31 | array(
32 | new ClassUsage('X\Foo', 5),
33 | new ClassUsage('Bar', 6),
34 | ),
35 | $phpFileInfo->classUsages()
36 | );
37 | }
38 |
39 | public function testNoNewStatement()
40 | {
41 | $source = <<<'EOC'
42 | prophesize('Symfony\Component\Finder\SplFileInfo');
49 | $usageCollection = $this->parsePhpFileFromStringAndTraverseWithVisitor(
50 | $file = PhpFileInfo::create($splFileInfo->reveal()),
51 | $source,
52 | new FindClasses()
53 | );
54 |
55 | $this->assertEquals(
56 | array(),
57 | $usageCollection->classUsages()
58 | );
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/tests/Visitor/Usage/FindInterfacesTest.php:
--------------------------------------------------------------------------------
1 | prophesize('Symfony\Component\Finder\SplFileInfo');
25 | $phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor(
26 | $file = PhpFileInfo::create($splFileInfo->reveal()),
27 | $source,
28 | new FindInterfaces()
29 | );
30 |
31 | $this->assertEquals(
32 | array('Foo\Bar' => array(new InterfaceUsage('Foo\Baz', 'Foo\Bar', 4))),
33 | $phpFileInfo->interfaceUsages()
34 | );
35 | }
36 |
37 | public function testClassWithoutInterface()
38 | {
39 | $source = <<prophesize('Symfony\Component\Finder\SplFileInfo');
48 | $phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor(
49 | $file = PhpFileInfo::create($splFileInfo->reveal()),
50 | $source,
51 | new FindInterfaces()
52 | );
53 |
54 | $this->assertEquals(
55 | array(),
56 | $phpFileInfo->interfaceUsages()
57 | );
58 | }
59 |
60 | public function testSkipsAnonymousClasses()
61 | {
62 | $phpFileInfo = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo');
63 | $phpFileInfo->addInterfaceUsage(Argument::any())->shouldNotBeCalled();
64 |
65 | $visitor = new FindInterfaces();
66 |
67 | $node = new Class_(
68 | null,
69 | array('implements' => array(new Name('SomeInterface')))
70 | );
71 |
72 | $visitor->enterNode($node);
73 | }
74 | }
75 |
--------------------------------------------------------------------------------
/tests/Visitor/Usage/FindLanguageDeprecationsTest.php:
--------------------------------------------------------------------------------
1 | prophesize('Symfony\Component\Finder\SplFileInfo');
20 | $phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor(
21 | $file = PhpFileInfo::create($splFileInfo->reveal()),
22 | $source,
23 | new FindLanguageDeprecations()
24 | );
25 |
26 | $this->assertEquals(
27 | array(),
28 | $phpFileInfo->getDeprecatedLanguageUsages()
29 | );
30 | }
31 |
32 | public function testPHP4Constructors()
33 | {
34 | $source = <<<'EOC'
35 | prophesize('Symfony\Component\Finder\SplFileInfo');
47 | $phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor(
48 | $file = PhpFileInfo::create($splFileInfo->reveal()),
49 | $source,
50 | new FindLanguageDeprecations()
51 | );
52 |
53 | $this->assertInstanceOf(
54 | 'SensioLabs\DeprecationDetector\FileInfo\Usage\DeprecatedLanguageUsage',
55 | $phpFileInfo->getDeprecatedLanguageUsages()[0]
56 | );
57 | }
58 |
59 | public function testNamespacedPHP4Constructors()
60 | {
61 | $source = <<<'EOC'
62 | prophesize('Symfony\Component\Finder\SplFileInfo');
76 | $phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor(
77 | $file = PhpFileInfo::create($splFileInfo->reveal()),
78 | $source,
79 | new FindLanguageDeprecations()
80 | );
81 |
82 | $this->assertEquals(
83 | array(),
84 | $phpFileInfo->getDeprecatedLanguageUsages()
85 | );
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/tests/Visitor/Usage/FindStaticMethodCallsTest.php:
--------------------------------------------------------------------------------
1 | assertInstanceOf('SensioLabs\DeprecationDetector\Visitor\Usage\FindStaticMethodCalls', $visitor);
15 | }
16 |
17 | public function testNoNewStatement()
18 | {
19 | $source = <<<'EOC'
20 | prophesize('Symfony\Component\Finder\SplFileInfo');
28 | $phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor(
29 | $file = PhpFileInfo::create($splFileInfo->reveal()),
30 | $source,
31 | new FindStaticMethodCalls()
32 | );
33 |
34 | $usages = $phpFileInfo->methodUsages();
35 | $this->assertEquals(
36 | new MethodUsage('bazinga', 'Bar', 3, true),
37 | $usages[0]
38 | );
39 | $this->assertEquals(
40 | new MethodUsage('log', 'Logger', 4, true),
41 | $usages[1]
42 | );
43 | }
44 | }
45 |
--------------------------------------------------------------------------------
/tests/Visitor/Usage/FindSuperTypesTest.php:
--------------------------------------------------------------------------------
1 | prophesize('Symfony\Component\Finder\SplFileInfo');
26 | $phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor(
27 | $file = PhpFileInfo::create($splFileInfo->reveal()),
28 | $source,
29 | new FindSuperTypes()
30 | );
31 |
32 | $this->assertEquals(
33 | array('Foo\Bar' => new SuperTypeUsage('Foo\Baz', 'Foo\Bar', 4)),
34 | $phpFileInfo->superTypeUsages()
35 | );
36 | }
37 |
38 | public function testNoSuperType()
39 | {
40 | $source = <<prophesize('Symfony\Component\Finder\SplFileInfo');
50 | $phpFileInfo = $this->parsePhpFileFromStringAndTraverseWithVisitor(
51 | $file = PhpFileInfo::create($splFileInfo->reveal()),
52 | $source,
53 | new FindSuperTypes()
54 | );
55 |
56 | $this->assertEquals(
57 | array(),
58 | $phpFileInfo->superTypeUsages()
59 | );
60 | }
61 |
62 | public function testSkipsAnonymousClasses()
63 | {
64 | $phpFileInfo = $this->prophesize('SensioLabs\DeprecationDetector\FileInfo\PhpFileInfo');
65 | $phpFileInfo->addSuperTypeUsage(Argument::any())->shouldNotBeCalled();
66 |
67 | $visitor = new FindSuperTypes();
68 |
69 | $node = new Class_(
70 | null,
71 | array('extends' => new Name('SomeInterface'))
72 | );
73 |
74 | $visitor->enterNode($node);
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/tests/Visitor/Usage/FindTestCase.php:
--------------------------------------------------------------------------------
1 | addVisitor(new NameResolver());
21 | $traverser->addVisitor($visitor->setPhpFileInfo($phpFileInfo));
22 | $parser = new Parser\Php7(new Emulative());
23 | $traverser->traverse($parser->parse($source));
24 |
25 | return $phpFileInfo;
26 | }
27 | }
28 |
--------------------------------------------------------------------------------