Passed
Pull Request — develop (#1)
by Andreas
03:30
created

Content::getSummaryText()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
namespace Wambo\Catalog\Model;
3
4
use Wambo\Catalog\Error\ContentException;
5
6
/**
7
 * Class Content contains a product title, summary and description text
8
 *
9
 * @package Wambo\Catalog\Model
10
 */
11
class Content
12
{
13
    const TITLE_MIN_LENGTH = 1;
14
    const TITLE_MAX_LENGTH = 60;
15
16
    const SUMMARY_MIN_LENGTH = 5;
17
    const SUMMARY_MAX_LENGTH = 140;
18
19
    /**
20
     * @var string
21
     */
22
    private $summaryText;
23
    /**
24
     * @var string
25
     */
26
    private $productDescription;
27
    /**
28
     * @var string
29
     */
30
    private $title;
31
32
    /**
33
     * Creates a new instance of a product Content model.
34
     *
35
     * @param string $title              A product title (e.g. "Fancy T-Shirt No. 1")
36
     * @param string $summaryText        A short description text of a product (e.g. "The first edition of our fancy
37
     *                                   T-Shirt with a unicorn pooping ice cream on the front"; optional)
38
     * @param string $productDescription A full product description text (optional)
39
     *
40
     * @throws ContentException If the summary text is too long
41
     */
42 25
    public function __construct(string $title, string $summaryText = "", string $productDescription = "")
43
    {
44
        // validate the title
45 25
        $title = trim($title);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $title. This often makes code more readable.
Loading history...
46 25
        if (strlen($title) < self::TITLE_MIN_LENGTH) {
47 2
            throw new ContentException(sprintf("The title should not be shorter than %s characters",
48 2
                self::TITLE_MIN_LENGTH));
49
        }
50
51 23
        if (strlen($title) > self::TITLE_MAX_LENGTH) {
52 1
            throw new ContentException(sprintf("The title should not be longer than %s characters",
53 1
                self::TITLE_MAX_LENGTH));
54
        }
55
56
        // validate the summary
57 22
        $summaryText = trim($summaryText);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $summaryText. This often makes code more readable.
Loading history...
58
59 22
        if (strlen($summaryText) < self::SUMMARY_MIN_LENGTH) {
60 2
            throw new ContentException(sprintf("The summary text should not be shorter than %s characters",
61 2
                self::SUMMARY_MIN_LENGTH));
62
        }
63
64 20
        if (strlen($summaryText) > self::SUMMARY_MAX_LENGTH) {
65 1
            throw new ContentException(sprintf("The summary text should not be longer than %s characters",
66 1
                self::SUMMARY_MAX_LENGTH));
67
        }
68
69 19
        $this->title = $title;
70 19
        $this->summaryText = $summaryText;
71 19
        $this->productDescription = $productDescription;
72 19
    }
73
74
    /**
75
     * Get the title of a product (e.g. "Fancy T-Shirt No. 1")
76
     *
77
     * @return string
78
     */
79 5
    public function getTitle()
80
    {
81 5
        return $this->title;
82
    }
83
84
    /**
85
     * Get a short description text of a product (e.g. "The first edition of our fancy T-Shirt with a unicorn pooping
86
     * ice cream on the front")
87
     *
88
     * @return string
89
     */
90 6
    public function getSummaryText()
91
    {
92 6
        return $this->summaryText;
93
    }
94
95
    /**
96
     * Get a full product description text
97
     *
98
     * @return string
99
     */
100 6
    public function getProductDescription()
101
    {
102 6
        return $this->productDescription;
103
    }
104
}