These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | use AspectMock\Test as test; |
||
0 ignored issues
–
show
|
|||
4 | |||
5 | class GitTest extends \Codeception\TestCase\Test |
||
6 | { |
||
7 | /** |
||
8 | * @var \AspectMock\Proxy\ClassProxy |
||
9 | */ |
||
10 | protected $git; |
||
11 | |||
12 | protected function _before() |
||
13 | { |
||
14 | $this->git = test::double('Robo\Task\Vcs\GitStack', [ |
||
0 ignored issues
–
show
It seems like
\AspectMock\Test::double...\Psr\Log\NullLogger())) can also be of type object<AspectMock\Proxy\InstanceProxy> . However, the property $git is declared as type object<AspectMock\Proxy\ClassProxy> . Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
15 | 'executeCommand' => new \AspectMock\Proxy\Anything(), |
||
16 | 'output' => new \Symfony\Component\Console\Output\NullOutput(), |
||
17 | 'logger' => new \Psr\Log\NullLogger(), |
||
18 | ]); |
||
19 | } |
||
20 | |||
21 | // tests |
||
22 | public function testGitStackRun() |
||
23 | { |
||
24 | (new \Robo\Task\Vcs\GitStack('git'))->stopOnFail()->add('-A')->pull()->run(); |
||
25 | $this->git->verifyInvoked('executeCommand', ['git add -A']); |
||
26 | $this->git->verifyInvoked('executeCommand', ['git pull']); |
||
27 | |||
28 | (new \Robo\Task\Vcs\GitStack('git'))->add('-A')->pull()->run(); |
||
29 | $this->git->verifyInvoked('executeCommand', ['git add -A && git pull']); |
||
30 | } |
||
31 | |||
32 | View Code Duplication | public function testGitStackCommands() |
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository.
Loading history...
|
|||
33 | { |
||
34 | $linuxCmd = "git clone http://github.com/consolidation-org/Robo && git pull && git add -A && git commit -m 'changed' && git push && git tag 0.6.0 && git push origin 0.6.0"; |
||
35 | |||
36 | $winCmd = 'git clone http://github.com/consolidation-org/Robo && git pull && git add -A && git commit -m "changed" && git push && git tag 0.6.0 && git push origin 0.6.0'; |
||
37 | |||
38 | $cmd = stripos(PHP_OS, 'WIN') === 0 ? $winCmd : $linuxCmd; |
||
39 | |||
40 | verify( |
||
41 | (new \Robo\Task\Vcs\GitStack()) |
||
42 | ->cloneRepo('http://github.com/consolidation-org/Robo') |
||
43 | ->pull() |
||
44 | ->add('-A') |
||
45 | ->commit('changed') |
||
46 | ->push() |
||
47 | ->tag('0.6.0') |
||
48 | ->push('origin', '0.6.0') |
||
49 | ->getCommand() |
||
50 | )->equals($cmd); |
||
51 | } |
||
52 | |||
53 | View Code Duplication | public function testGitStackCommandsWithTagMessage() |
|
54 | { |
||
55 | $linuxCmd = "git clone http://github.com/consolidation-org/Robo && git pull && git add -A && git commit -m 'changed' && git push && git tag -m 'message' 0.6.0 && git push origin 0.6.0"; |
||
56 | |||
57 | $winCmd = 'git clone http://github.com/consolidation-org/Robo && git pull && git add -A && git commit -m "changed" && git push && git tag -m \'message\' 0.6.0 && git push origin 0.6.0'; |
||
58 | |||
59 | $cmd = stripos(PHP_OS, 'WIN') === 0 ? $winCmd : $linuxCmd; |
||
60 | |||
61 | verify( |
||
62 | (new \Robo\Task\Vcs\GitStack()) |
||
63 | ->cloneRepo('http://github.com/consolidation-org/Robo') |
||
64 | ->pull() |
||
65 | ->add('-A') |
||
66 | ->commit('changed') |
||
67 | ->push() |
||
68 | ->tag('0.6.0', 'message') |
||
69 | ->push('origin', '0.6.0') |
||
70 | ->getCommand() |
||
71 | )->equals($cmd); |
||
72 | } |
||
73 | |||
74 | public function testGitStackShallowCloneCommand() |
||
75 | { |
||
76 | $cmd = 'git clone --depth 1 http://github.com/consolidation-org/Robo ./deployment-path'; |
||
77 | |||
78 | verify( |
||
79 | (new \Robo\Task\Vcs\GitStack()) |
||
80 | ->cloneShallow('http://github.com/consolidation-org/Robo', './deployment-path') |
||
81 | ->getCommand() |
||
82 | )->equals($cmd); |
||
83 | } |
||
84 | |||
85 | public function testGitStackShallowCloneCommandWithDifferentDepth() |
||
86 | { |
||
87 | $cmd = 'git clone --depth 3 http://github.com/consolidation-org/Robo . --branch feature'; |
||
88 | |||
89 | verify( |
||
90 | (new \Robo\Task\Vcs\GitStack()) |
||
91 | ->cloneShallow('http://github.com/consolidation-org/Robo', '.', 'feature', 3) |
||
92 | ->getCommand() |
||
93 | )->equals($cmd); |
||
94 | } |
||
95 | } |
||
96 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: