| Total Complexity | 6 |
| Total Lines | 78 |
| Duplicated Lines | 19.23 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 19 | class AnnotatePermissionCheckerTest extends SapphireTest |
||
| 20 | { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var AnnotatePermissionChecker $permissionChecker |
||
| 24 | */ |
||
| 25 | private $permissionChecker = null; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var MockDataObjectAnnotator |
||
|
1 ignored issue
–
show
|
|||
| 29 | */ |
||
| 30 | private $annotator; |
||
| 31 | |||
| 32 | |||
| 33 | /** |
||
| 34 | * Setup Defaults |
||
| 35 | */ |
||
| 36 | protected function setUp() |
||
| 37 | { |
||
| 38 | parent::setUp(); |
||
| 39 | Config::modify()->set(Director::class, 'environment_type', 'dev'); |
||
| 40 | Config::modify()->set(DataObjectAnnotator::class, 'enabled', true); |
||
| 41 | Config::modify()->set(DataObjectAnnotator::class, 'enabled_modules', ['ideannotator', 'mysite']); |
||
| 42 | |||
| 43 | Config::modify()->merge(Team::class, 'extensions', [Team_Extension::class]); |
||
|
2 ignored issues
–
show
|
|||
| 44 | |||
| 45 | $this->annotator = Injector::inst()->get(MockDataObjectAnnotator::class); |
||
| 46 | $this->permissionChecker = Injector::inst()->get(AnnotatePermissionChecker::class); |
||
| 47 | } |
||
| 48 | |||
| 49 | View Code Duplication | public function testIsEnabled() |
|
| 50 | { |
||
| 51 | $this->assertTrue($this->permissionChecker->isEnabled()); |
||
| 52 | |||
| 53 | Config::inst()->remove(DataObjectAnnotator::class, 'enabled'); |
||
| 54 | Config::modify()->set(DataObjectAnnotator::class, 'enabled', false); |
||
| 55 | $this->assertFalse($this->permissionChecker->isEnabled()); |
||
| 56 | } |
||
| 57 | |||
| 58 | View Code Duplication | public function testAnnotatePermissionChecker() |
|
| 59 | { |
||
| 60 | Config::modify()->set(DataObjectAnnotator::class, 'enabled', false); |
||
| 61 | $this->assertFalse($this->permissionChecker->environmentIsAllowed()); |
||
| 62 | Config::modify()->set(DataObjectAnnotator::class, 'enabled', true); |
||
| 63 | $this->assertTrue($this->permissionChecker->environmentIsAllowed()); |
||
| 64 | } |
||
| 65 | |||
| 66 | /** |
||
| 67 | * Test is a module name is in the @Config enabled_modules |
||
| 68 | * and will be seen as allowed or disallowed correctly |
||
| 69 | */ |
||
| 70 | public function testModuleIsAllowed() |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Test if a DataObject is in an allowed module name |
||
| 79 | * and will be seen as allowed or disallowed correctly |
||
| 80 | */ |
||
| 81 | public function testDataObjectIsAllowed() |
||
| 82 | { |
||
| 83 | $this->assertTrue($this->permissionChecker->classNameIsAllowed(Team::class)); |
||
| 84 | $this->assertTrue($this->permissionChecker->classNameIsAllowed(Team_Extension::class)); |
||
| 85 | |||
| 86 | $this->assertFalse($this->permissionChecker->classNameIsAllowed(DataObject::class)); |
||
| 87 | $this->assertFalse($this->permissionChecker->classNameIsAllowed(File::class)); |
||
| 88 | |||
| 89 | Config::inst()->remove(DataObjectAnnotator::class, 'enabled_modules'); |
||
| 90 | Config::modify()->set(DataObjectAnnotator::class, 'enabled_modules', array('mysite')); |
||
| 91 | |||
| 92 | $this->assertFalse($this->permissionChecker->classNameIsAllowed(Team::class)); |
||
| 93 | } |
||
| 94 | public function tearDown() |
||
| 97 | } |
||
| 98 | } |
||
| 99 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths