Blog   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 27.78 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
c 2
b 0
f 0
lcom 1
cbo 0
dl 10
loc 36
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 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
3
namespace Borfast\Socializr;
4
5
class Blog
6
{
7
    public $id = '';
8
    public $title = '';
9
    public $link = '';
10
    public $posts = 0;
11
    public $name = '';
12
    public $updated;
13
    public $description = '';
14
    public $ask = false;
15
    public $ask_anon;
16
    public $followers = 0;
17
18
    /**
19
     * Create a new Blog object based on an array of attributes and a mapping
20
     * from those attributes to the Blog object's attributes.
21
     *
22
     * The keys are the name of the Blog object attributes, while the values
23
     * are the key of that attribute in the $attributes array. Like so:
24
     * ['blog_object_attribute' => 'key_in_attributes_array']
25
     *
26
     * @param array $mapping
27
     * @param array $attributes
28
     * @return static
29
     */
30 View Code Duplication
    public static function create(array $mapping, array $attributes)
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...
31
    {
32
        $blog = new Blog;
33
34
        array_walk($mapping, function (&$name, $key) use (&$blog, &$attributes) {
35
            $blog->$key = (isset($attributes[$name])) ? $attributes[$name] : null;
36
        });
37
38
        return $blog;
39
    }
40
}
41