These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | /** |
||
4 | * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0 |
||
5 | * @copyright Aimeos (aimeos.org), 2015-2016 |
||
6 | * @package MW |
||
7 | * @subpackage Filesystem |
||
8 | */ |
||
9 | |||
10 | |||
11 | namespace Aimeos\MW\Filesystem; |
||
12 | |||
13 | use League\Flysystem\Filesystem; |
||
14 | use League\Flysystem\Replicate\ReplicateAdapter; |
||
15 | |||
16 | |||
17 | /** |
||
18 | * Implementation of Flysystem Replicate file system adapter |
||
19 | * |
||
20 | * @package MW |
||
21 | * @subpackage Filesystem |
||
22 | */ |
||
23 | class FlyReplicate extends FlyBase implements Iface, DirIface, MetaIface |
||
24 | { |
||
25 | private $fs; |
||
26 | |||
27 | |||
28 | /** |
||
29 | * Returns the file system provider |
||
30 | * |
||
31 | * @return \League\Flysystem\FilesystemInterface File system provider |
||
32 | */ |
||
33 | protected function getProvider() |
||
34 | { |
||
35 | if( !isset( $this->fs ) ) |
||
36 | { |
||
37 | $config = $this->getConfig(); |
||
38 | |||
39 | if( !isset( $config['source'] ) ) { |
||
40 | throw new Exception( sprintf( 'Configuration option "%1$s" missing', 'source' ) ); |
||
41 | } |
||
42 | |||
43 | if( !isset( $config['replica'] ) ) { |
||
44 | throw new Exception( sprintf( 'Configuration option "%1$s" missing', 'replica' ) ); |
||
45 | } |
||
46 | |||
47 | $source = Factory::create( (array) $config['source'] )->getAdapter(); |
||
0 ignored issues
–
show
|
|||
48 | $replica = Factory::create( (array) $config['replica'] )->getAdapter(); |
||
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Aimeos\MW\Filesystem\Iface as the method getAdapter() does only exist in the following implementations of said interface: Aimeos\MW\Filesystem\FlyAwsS3 , Aimeos\MW\Filesystem\FlyAzure , Aimeos\MW\Filesystem\FlyBase , Aimeos\MW\Filesystem\FlyDropbox , Aimeos\MW\Filesystem\FlyFtp , Aimeos\MW\Filesystem\FlyGridfs , Aimeos\MW\Filesystem\FlyLocal , Aimeos\MW\Filesystem\FlyMemory , Aimeos\MW\Filesystem\FlyNone , Aimeos\MW\Filesystem\FlyPhpcr , Aimeos\MW\Filesystem\FlyRackspace , Aimeos\MW\Filesystem\FlyReplicate , Aimeos\MW\Filesystem\FlySftp , Aimeos\MW\Filesystem\FlyWebdav , Aimeos\MW\Filesystem\FlyZip .
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
49 | $this->fs = new Filesystem( new ReplicateAdapter( $source, $replica ) ); |
||
50 | } |
||
51 | |||
52 | return $this->fs; |
||
53 | } |
||
54 | } |
||
55 |
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: