Passed
Branch master (79d24d)
by Johannes
02:27
created

PropertyMetadata   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getValue() 4 4 1
A setValue() 4 4 1
A __construct() 8 8 1
A serialize() 7 7 1
A unserialize() 7 7 1

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
/*
0 ignored issues
show
introduced by
Copyright notice too long
Loading history...
4
 * Copyright 2011 Johannes M. Schmitt <[email protected]>
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Metadata;
20
21
/**
22
 * Base class for property metadata.
23
 *
24
 * This class is intended to be extended to add your application specific
25
 * properties, and flags.
26
 *
27
 * @author Johannes M. Schmitt <[email protected]>
28
 */
29 View Code Duplication
class PropertyMetadata implements \Serializable
0 ignored issues
show
Duplication introduced by
This class 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...
30
{
31
    public $class;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
32
    public $name;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
33
    public $reflection;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
34
35
    public function __construct($class, $name)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
36
    {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
37
        $this->class = $class;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
38
        $this->name = $name;
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
39
40
        $this->reflection = new \ReflectionProperty($class, $name);
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
41
        $this->reflection->setAccessible(true);
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
42
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
43
44
    /**
0 ignored issues
show
introduced by
Missing short description in doc comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
45
     * @param object $obj
0 ignored issues
show
introduced by
Missing parameter comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
46
     *
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
47
     * @return mixed
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
48
     */
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
49
    public function getValue($obj)
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
50
    {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
51
        return $this->reflection->getValue($obj);
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
52
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
53
54
    /**
0 ignored issues
show
introduced by
Missing short description in doc comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
55
     * @param object $obj
0 ignored issues
show
introduced by
Missing parameter comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
56
     * @param string $value
0 ignored issues
show
introduced by
Missing parameter comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
57
     */
0 ignored issues
show
introduced by
Missing @return tag in function comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
58
    public function setValue($obj, $value)
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
59
    {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
60
        $this->reflection->setValue($obj, $value);
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
61
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
62
63
    public function serialize()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
64
    {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
65
        return serialize(array(
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
66
            $this->class,
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
67
            $this->name,
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
68
        ));
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
69
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
70
71
    public function unserialize($str)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
72
    {
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
73
        list($this->class, $this->name) = unserialize($str);
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
74
75
        $this->reflection = new \ReflectionProperty($this->class, $this->name);
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
76
        $this->reflection->setAccessible(true);
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
77
    }
0 ignored issues
show
introduced by
Tabs must be used to indent lines; spaces are not allowed
Loading history...
78
}
79