ConnectsToCloudStorage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 46
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A dropbox() 0 6 1
A google() 0 6 1
A googleDrive() 0 4 1
A getCloudStorage() 0 6 2
1
<?php
2
3
namespace STS\StorageConnect\Traits;
4
5
use Illuminate\Database\Eloquent\Relations\MorphOne;
6
use STS\StorageConnect\Models\CloudStorage;
7
8
/**
9
 * Class ConnectsToCloudStorage
10
 * @package STS\StorageConnect\Traits
11
 */
12
trait ConnectsToCloudStorage
13
{
14
    protected $supportedCloudStorage = ["dropbox", "google"];
15
16
    /**
17
     * @return MorphOne
18
     */
19
    public function dropbox()
20
    {
21
        return $this->morphOne(CloudStorage::class, 'owner')->whereDriver('dropbox')->withDefault([
0 ignored issues
show
Bug introduced by
It seems like morphOne() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
22
            'driver' => 'dropbox',
23
        ]);
24
    }
25
26
    /**
27
     * @return MorphOne
28
     */
29
    public function google()
30
    {
31
        return $this->morphOne(CloudStorage::class, 'owner')->whereDriver('google')->withDefault([
0 ignored issues
show
Bug introduced by
It seems like morphOne() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
32
            'driver' => 'google',
33
        ]);
34
    }
35
36
    /**
37
     * Alias
38
     *
39
     * @return MorphOne
40
     */
41
    public function googleDrive()
42
    {
43
        return $this->google();
44
    }
45
46
    /**
47
     * @param $driver
48
     *
49
     * @return CloudStorage
50
     */
51
    public function getCloudStorage($driver)
52
    {
53
        if (in_array($driver, $this->supportedCloudStorage)) {
54
            return $this->{$driver};
55
        }
56
    }
57
}