Copy   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 7
Bugs 1 Features 2
Metric Value
c 7
b 1
f 2
dl 0
loc 38
wmc 4
lcom 1
cbo 1
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setCopy() 0 18 3
A getCopy() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of the Axstrad library.
5
 *
6
 * (c) Dan Kempster <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 *
11
 * @copyright 2014-2015 Dan Kempster <[email protected]>
12
 */
13
14
namespace Axstrad\Component\Content\Traits;
15
16
use Axstrad\Component\Content\Exception\InvalidArgumentException;
17
18
/**
19
 * Axstrad\Component\Content\Traits\Copy
20
 *
21
 * Property requirements
22
 *   - $copy = null
23
 *
24
 * @author Dan Kempster <[email protected]>
25
 * @license MIT
26
 * @package Axstrad/Content
27
 * @since 0.3
28
 */
29
trait Copy
30
{
31
    /**
32
     * Set Copy
33
     *
34
     * @param string $copy
35
     * @return self
36
     */
37 78
    public function setCopy($copy = null)
38
    {
39 78
        if (is_null($copy)) {
40
            /** @noinspection PhpUndefinedFieldInspection */
41 15
            $this->copy = null;
0 ignored issues
show
Bug introduced by
The property copy 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...
42 15
        }
43 78
        elseif (!is_scalar($copy)) {
44 15
            throw InvalidArgumentException::create(
45 15
                'string (or scalar)',
46
                $copy
47 15
            );
48
        }
49
        else {
50
            /** @noinspection PhpUndefinedFieldInspection */
51 63
            $this->copy = (string) $copy;
52
        }
53 63
        return $this;
54
    }
55
56
    /**
57
     * Get copy
58
     *
59
     * @return string
60
     */
61 69
    public function getCopy()
62
    {
63
        /** @noinspection PhpUndefinedFieldInspection */
64 69
        return $this->copy;
65
    }
66
}
67