Passed
Push — develop ( 5f0710...340c0b )
by Neill
12:23 queued 14s
created

S3   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
eloc 21
dl 0
loc 58
rs 10
c 0
b 0
f 0
ccs 0
cts 24
cp 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A init() 0 12 4
A getAdapter() 0 11 1
1
<?php
2
/**
3
 * @link http://www.newicon.net/neon
4
 * @copyright Copyright (c) 2016 Newicon Ltd
5
 * @license http://www.newicon.net/neon/license/
6
 * @author Steve O'Brien <[email protected]> 23/11/2016 17:20
7
 * @package neon
8
 */
9
10
namespace neon\firefly\services\driveManager\drivers;
11
12
use \yii\base\Component;
13
use yii\base\InvalidConfigException;
14
use \neon\firefly\services\driveManager\interfaces\IDriverConfig;
15
16
// Amazon dependancies
17
use Aws\S3\S3Client;
0 ignored issues
show
Bug introduced by
The type Aws\S3\S3Client 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...
18
use League\Flysystem\AwsS3v3\AwsS3Adapter;
0 ignored issues
show
Bug introduced by
The type League\Flysystem\AwsS3v3\AwsS3Adapter 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...
19
20
/**
21
 * Provides the Amazon S3 adapter
22
 * ----------------------------------------------------------------------------
23
 *  Note this requires league/flysystem-aws-s3-v3
24
 * `composer require league/flysystem-aws-s3-v3`
25
 * ----------------------------------------------------------------------------
26
 *
27
 * @depends league/flysystem-aws-s3-v2
28
 * @author Alexander Kochetov <[email protected]>
29
 */
30
class S3 extends Component implements IDriverConfig
31
{
32
	/**
33
	 * @var string
34
	 */
35
	public $key;
36
	/**
37
	 * @var string
38
	 */
39
	public $secret;
40
	/**
41
	 * @var string
42
	 */
43
	public $region = 's3-eu-west-1';
44
	/**
45
	 * @var string
46
	 */
47
	public $bucket;
48
	/**
49
	 * @var string|null
50
	 */
51
	public $prefix;
52
	/**
53
	 * @var string 'latest'|'version'
54
	 */
55
	public $version = 'latest';
56
57
	/**
58
	 * @inheritdoc
59
	 */
60
	public function init()
61
	{
62
		if ($this->key === null) {
63
			throw new InvalidConfigException('The "key" property must be set.');
64
		}
65
		if ($this->secret === null) {
66
			throw new InvalidConfigException('The "secret" property must be set.');
67
		}
68
		if ($this->bucket === null) {
69
			throw new InvalidConfigException('The "bucket" property must be set.');
70
		}
71
		parent::init();
72
	}
73
74
	/**
75
	 * @return AwsS3Adapter
76
	 */
77
	public function getAdapter()
78
	{
79
		$client = S3Client::factory([
80
			'credentials' => [
81
				'key' => $this->key,
82
				'secret' => $this->secret,
83
			],
84
			'region' => $this->region,
85
			'version' => $this->version,
86
		]);
87
		return new AwsS3Adapter($client, $this->bucket, $this->prefix);
88
	}
89
}
90