Introduction::setIntroduction()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 18
ccs 10
cts 10
cp 1
rs 9.4286
cc 3
eloc 10
nc 3
nop 1
crap 3
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\Bundle\ContentBundle\Traits\Introduction
20
 *
21
 * Property requirements
22
 *   - $introduction = null
23
 *
24
 * @author Dan Kempster <[email protected]>
25
 * @license MIT
26
 * @package Axstrad/Content
27
 * @since 0.3
28
 */
29
trait Introduction
30
{
31
    /**
32
     * Set introduction
33
     *
34
     * @param null|string $introduction
35
     * @return self
36
     */
37 35
    public function setIntroduction($introduction = null)
38
    {
39 35
        if ($introduction === null) {
40
            /** @noinspection PhpUndefinedFieldInspection */
41 7
            $this->introduction = null;
0 ignored issues
show
Bug introduced by
The property introduction 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 7
        }
43 35
        elseif (!is_scalar($introduction)) {
44 7
            throw InvalidArgumentException::create(
45 7
                'null or string',
46
                $introduction
47 7
            );
48
        }
49
        else {
50
            /** @noinspection PhpUndefinedFieldInspection */
51 28
            $this->introduction = (string) $introduction;
52
        }
53 28
        return $this;
54
    }
55
56
    /**
57
     * Get introduction
58
     *
59
     * @return null|string
60
     */
61 29
    public function getIntroduction()
62
    {
63
        /** @noinspection PhpUndefinedFieldInspection */
64 29
        return $this->introduction;
65
    }
66
}
67