-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from DaveLiddament/feature/add-injectable-version
ADD InjectableVersion Attribute
- Loading branch information
Showing
12 changed files
with
401 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
examples/injectableVersion/InjectableVersionCheckOnMethod.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace InjectableVersionCheckOnMethod; | ||
|
||
use DaveLiddament\PhpLanguageExtensions\CheckInjectableVersion; | ||
use DaveLiddament\PhpLanguageExtensions\InjectableVersion; | ||
|
||
#[InjectableVersion] | ||
abstract class Repository | ||
{ | ||
} | ||
|
||
class DoctrineRepository extends Repository | ||
{ | ||
} | ||
|
||
class InjectingCorrectVersion | ||
{ | ||
public Repository $repository; | ||
|
||
#[CheckInjectableVersion] | ||
public function setRepository(Repository $repository): void // OK | ||
{ | ||
$this->repository = $repository; | ||
} | ||
} | ||
|
||
class InjectingWrongVersion | ||
{ | ||
public Repository $repository; | ||
|
||
#[CheckInjectableVersion] | ||
public function setRepository(DoctrineRepository $repository): void // ERROR | ||
{ | ||
$this->repository = $repository; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace InjectableVersionOnClass; | ||
|
||
use DaveLiddament\PhpLanguageExtensions\InjectableVersion; | ||
|
||
#[InjectableVersion] | ||
abstract class Repository | ||
{ | ||
} | ||
|
||
class DoctrineRepository extends Repository | ||
{ | ||
} | ||
|
||
|
||
class InjectingCorrectVersion | ||
{ | ||
public function __construct( | ||
public Repository $repository, | ||
public int $int | ||
) {} // OK | ||
} | ||
|
||
class InjectingWrongVersion | ||
{ | ||
/** @param mixed $unknownType */ | ||
public function __construct( | ||
public string $string, | ||
public $unknownType, | ||
public DoctrineRepository $repository | ||
) {} // ERROR | ||
} |
31 changes: 31 additions & 0 deletions
31
examples/injectableVersion/InjectableVersionOnExtendsThenImplements.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace InjectableVersionOnExtendsThenImplements; | ||
|
||
use DaveLiddament\PhpLanguageExtensions\InjectableVersion; | ||
|
||
#[InjectableVersion] | ||
interface Repository | ||
{ | ||
} | ||
|
||
class AbstractDoctrineRepository implements Repository | ||
{ | ||
} | ||
|
||
|
||
class DoctrineRepository extends AbstractDoctrineRepository | ||
{ | ||
} | ||
|
||
class InjectingWrongVersion1 | ||
{ | ||
public function __construct(public AbstractDoctrineRepository $repository) {} // ERROR | ||
} | ||
|
||
class InjectingWrongVersion2 | ||
{ | ||
public function __construct(public DoctrineRepository $repository) {} // ERROR | ||
} |
27 changes: 27 additions & 0 deletions
27
examples/injectableVersion/InjectableVersionOnInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace InjectableVersionOnInterface; | ||
|
||
use DaveLiddament\PhpLanguageExtensions\InjectableVersion; | ||
|
||
#[InjectableVersion] | ||
interface Repository | ||
{ | ||
} | ||
|
||
interface DoctrineRepository extends Repository | ||
{ | ||
} | ||
|
||
|
||
class InjectingCorrectVersion | ||
{ | ||
public function __construct(public Repository $repository) {} | ||
} | ||
|
||
class InjectingWrongVersion | ||
{ | ||
public function __construct(public DoctrineRepository $repository) {} | ||
} |
31 changes: 31 additions & 0 deletions
31
examples/injectableVersion/InjectableVersionRulesIgnoredForTestNamespace.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace InjectableVersionRulesIgnoredForTestNamespace { | ||
|
||
use DaveLiddament\PhpLanguageExtensions\InjectableVersion; | ||
|
||
#[InjectableVersion] | ||
interface Repository | ||
{ | ||
} | ||
} | ||
|
||
|
||
namespace InjectableVersionRulesIgnoredForTestNamespace\Test { | ||
|
||
use InjectableVersionRulesIgnoredForTestNamespace\Repository; | ||
|
||
class RepositoryDouble implements Repository | ||
{ | ||
} | ||
|
||
class ServiceDouble | ||
{ | ||
public function __construct(public RepositoryDouble $repository) // OK as in test namespace and this excluded from checks | ||
{ | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace IterableInjectableVersion; | ||
|
||
use DaveLiddament\PhpLanguageExtensions\InjectableVersion; | ||
|
||
#[InjectableVersion] | ||
abstract class Repository | ||
{ | ||
} | ||
|
||
class DoctrineRepository extends Repository | ||
{ | ||
} | ||
|
||
|
||
class InjectingCorrectVersion | ||
{ | ||
/** @param Repository[] $repositories */ | ||
public function __construct(public array $repositories) {} // OK | ||
} | ||
|
||
class InjectingWrongVersion | ||
{ | ||
/** @param DoctrineRepository[] $repositories */ | ||
public function __construct(public iterable $repositories) {} // ERROR | ||
} | ||
|
||
class InjectingWrongVersion2 | ||
{ | ||
/** @param DoctrineRepository[] $repositories */ | ||
public function __construct($repositories) {var_export($repositories);} // ERROR | ||
} |
37 changes: 37 additions & 0 deletions
37
examples/injectableVersion/MultipleLevelsOfInheritanceInjectableVersionOnInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MultipleLevelsOfInheritanceOnInjectableVersionOnInterface; | ||
|
||
use DaveLiddament\PhpLanguageExtensions\InjectableVersion; | ||
|
||
#[InjectableVersion] | ||
interface CorrectVersion | ||
{ | ||
} | ||
|
||
interface FirstLevelOfInheritance extends CorrectVersion | ||
{ | ||
} | ||
|
||
|
||
class SecondLevelOfInheritance implements FirstLevelOfInheritance | ||
{ | ||
} | ||
|
||
|
||
class InjectingCorrectVersion | ||
{ | ||
public function __construct(public CorrectVersion $repository) {} // OK | ||
} | ||
|
||
class InjectingWrongVersion1 | ||
{ | ||
public function __construct(public FirstLevelOfInheritance $repository) {} // ERROR | ||
} | ||
|
||
class InjectingWrongVersion2 | ||
{ | ||
public function __construct(public SecondLevelOfInheritance $repository) {} // ERROR | ||
} |
35 changes: 35 additions & 0 deletions
35
examples/injectableVersion/MultipleLevelsOfInheritanceNoInjectableVersionOnClass.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace MultipleLevelsOfInheritanceNoInjectableVersionOnClass; | ||
|
||
|
||
class CorrectVersion | ||
{ | ||
} | ||
|
||
class FirstLevelOfInheritance extends CorrectVersion | ||
{ | ||
} | ||
|
||
|
||
class SecondLevelOfInheritance extends FirstLevelOfInheritance | ||
{ | ||
} | ||
|
||
|
||
class InjectingCorrectVersion | ||
{ | ||
public function __construct(public CorrectVersion $repository) {} // OK | ||
} | ||
|
||
class InjectingWrongVersion1 | ||
{ | ||
public function __construct(public FirstLevelOfInheritance $repository) {} // OK | ||
} | ||
|
||
class InjectingWrongVersion2 | ||
{ | ||
public function __construct(public SecondLevelOfInheritance $repository) {} // OK | ||
} |
Oops, something went wrong.