Test Failed
Pull Request — master (#38)
by Maximo
04:25
created

FileSystemProvider::register()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.686

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 1
nop 1
dl 0
loc 16
ccs 4
cts 9
cp 0.4444
crap 2.686
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace Gewaer\Providers;
4
5
use Phalcon\Di\ServiceProviderInterface;
6
use Phalcon\DiInterface;
7
use League\Flysystem\Adapter\Local;
8
use League\Flysystem\AwsS3v3\AwsS3Adapter;
9
use League\Flysystem\Filesystem;
10
use Aws\S3\S3Client;
11
12
class FileSystemProvider implements ServiceProviderInterface
13
{
14
    /**
15
     * @param DiInterface $container
16
     */
17 54
    public function register(DiInterface $container)
18
    {
19 54
        $config = $container->getShared('config');
20
21 54
        $container->setShared(
22 54
            'filesystem',
23
            function ($filesystem = 'local') use ($config) {
24
                if ($filesystem === 'local') {
25
                    //create directory
26
                    $adapter = new Local($config->filesystem->local->path);
27
                } else {
28
                    //s3
29
                    $client = new S3Client($config->filesystem->s3->info->toArray());
30
                    $adapter = new AwsS3Adapter($client, $config->filesystem->s3->bucket, null, ['ACL' => 'public-read']);
31
                }
32
                return new Filesystem($adapter);
33 54
            }
34
        );
35 54
    }
36
}
37