Completed
Push — master ( 8ae150...af2d08 )
by Timur
02:28
created

FilesTransformer::getFilesCollectionFromArrays()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
1
<?php
2
3
namespace ArgentCrusade\Selectel\CloudStorage\Traits;
4
5
use ArgentCrusade\Selectel\CloudStorage\Collections\Collection;
6
use ArgentCrusade\Selectel\CloudStorage\File;
7
8
trait FilesTransformer
9
{
10
    /**
11
     * Transforms file array to instance of File object.
12
     *
13
     * @param array $file File array.
14
     *
15
     * @return \ArgentCrusade\Selectel\CloudStorage\Contracts\FileContract
16
     */
17
    public function getFileFromArray(array $file)
18
    {
19
        return new File($this->api, $this->containerName, $file);
0 ignored issues
show
Bug introduced by
The property api does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
Bug introduced by
The property containerName does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
20
    }
21
22
    /**
23
     * Transforms Collection of file arrays (or plain array) to Collection of File objects.
24
     * Warning: converting a lot of files to `File` instances may result in performance loss.
25
     *
26
     * @param array|\ArgentCrusade\Selectel\CloudStorage\Collections\Collection $files
27
     *
28
     * @return \ArgentCrusade\Selectel\CloudStorage\Collections\Collection
29
     */
30
    public function getFilesCollectionFromArrays($files)
31
    {
32
        $collection = new Collection();
33
34
        foreach ($files as $file) {
35
            $collection[] = $this->getFileFromArray($file);
36
        }
37
38
        return $collection;
39
    }
40
}
41