Completed
Push — master ( 2994aa...19d116 )
by Patrick
08:28
created

FileRequestCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 19.23 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 2
dl 10
loc 52
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCollectionItemsKey() 0 4 1
A __construct() 0 7 2
A processItems() 10 10 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
namespace Dropbox\Models;
3
4
class FileRequestCollection extends ModelCollection
5
{
6
7
    /**
8
     * Collection Items Key
9
     *
10
     * @const string
11
     */
12
    const COLLECTION_ITEMS_KEY = 'file_requests';
13
14
    /**
15
     * Get the Collection Items Key
16
     *
17
     * @return string
18
     */
19
    public function getCollectionItemsKey()
20
    {
21
        return static::COLLECTION_ITEMS_KEY;
22
    }
23
24
    /**
25
     * Create a new FileRequest Collection
26
     *
27
     * @param array $data Collection Data
28
     */
29
    public function __construct(array $data)
30
    {
31
        $this->data = $data;
32
33
        $items = isset($data[$this->getCollectionItemsKey()]) ? $data[$this->getCollectionItemsKey()] : [];
34
        $this->processItems($items);
35
    }
36
37
    /**
38
     * Process items and cast them
39
     * to their respective Models
40
     *
41
     * @param array $items Unprocessed Items
42
     *
43
     * @return void
44
     */
45 View Code Duplication
    protected function processItems(array $items)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
46
    {
47
        $processedItems = [];
48
49
        foreach ($items as $entry) {
50
            $processedItems[] = ModelFactory::make($entry);
51
        }
52
53
        $this->items = new ModelCollection($processedItems);
54
    }
55
}
56