FlySftp   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 57
rs 10
c 0
b 0
f 0
wmc 5

1 Method

Rating   Name   Duplication   Size   Complexity  
A getProvider() 0 47 5
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2024
6
 * @package Base
7
 * @subpackage Filesystem
8
 */
9
10
11
namespace Aimeos\Base\Filesystem;
12
13
use League\Flysystem\Filesystem;
14
use League\Flysystem\PhpseclibV2\SftpAdapter;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\PhpseclibV2\SftpAdapter was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use League\Flysystem\PhpseclibV2\SftpConnectionProvider;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\Phpsecl...\SftpConnectionProvider was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use League\Flysystem\UnixVisibility\PortableVisibilityConverter;
17
18
19
/**
20
 * Implementation of Flysystem SFTP file system adapter
21
 *
22
 * @package Base
23
 * @subpackage Filesystem
24
 */
25
class FlySftp extends FlyBase implements Iface, DirIface, MetaIface
26
{
27
	private ?Filesystem $fs = null;
28
29
30
	/**
31
	 * Returns the file system provider
32
	 *
33
	 * @return \League\Flysystem\Filesystem File system provider
34
	 */
35
	protected function getProvider()
36
	{
37
		if( !isset( $this->fs ) )
38
		{
39
			$config = $this->getConfig();
40
41
			if( !isset( $config['host'] ) ) {
42
				throw new Exception( sprintf( 'Configuration option "%1$s" missing', 'host' ) );
43
			}
44
45
			if( !isset( $config['username'] ) ) {
46
				throw new Exception( sprintf( 'Configuration option "%1$s" missing', 'username' ) );
47
			}
48
49
			if( !isset( $config['root'] ) ) {
50
				throw new Exception( sprintf( 'Configuration option "%1$s" missing', 'root' ) );
51
			}
52
53
			$provider = new SftpConnectionProvider(
54
				$config['host'],
55
				$config['username'],
56
				$config['password'] ?? null,
57
				$config['privateKey'] ?? null,
58
				$config['passphrase'] ?? null,
59
				$config['port'] ?? 22,
60
				$config['agent'] ?? false,
61
				$config['timeout'] ?? 10,
62
				$config['retry'] ?? 4,
63
				$config['fingerprint'] ?? null
64
			);
65
66
			$converter = PortableVisibilityConverter::fromArray( [
67
				'file' => [
68
					'public' => 0640,
69
					'private' => 0604,
70
				],
71
				'dir' => [
72
					'public' => 0740,
73
					'private' => 7604,
74
				],
75
			] );
76
77
78
			$this->fs = new Filesystem( new SftpAdapter( $provider, $config['root'], $converter ) );
79
		}
80
81
		return $this->fs;
82
	}
83
}
84