Test Setup Failed
Pull Request — develop (#1)
by Andreas
04:24
created

Content   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 3
A getSummaryText() 0 4 1
A getProductDescription() 0 4 1
1
<?php
2
namespace Wambo\Catalog\Model;
3
4
use Wambo\Catalog\Error\ContentException;
5
6
/**
7
 * Class Content contains the product summary and description text
8
 *
9
 * @package Wambo\Catalog\Model
10
 */
11
class Content
12
{
13
    const SUMMARY_MIN_LENGTH = 5;
14
    const SUMMARY_MAX_LENGTH = 140;
15
16
    /**
17
     * @var string
18
     */
19
    private $summaryText;
20
    /**
21
     * @var string
22
     */
23
    private $productDescription;
24
25
    /**
26
     * Creates a new instance of the product Content model.
27
     *
28
     * @param string $summaryText        A short description text of the product (e.g. "The first edition of our fancy
29
     *                                   T-Shirt with a unicorn pooping ice cream on the front"; optional)
30
     * @param string $productDescription A full product description text (optional)
31
     *
32
     * @throws ContentException If the summary text is too short
33
     * @throws ContentException If the summary text is too long
34
     */
35
    public function __construct(string $summaryText = "", string $productDescription = "")
36
    {
37
        // trim the summary
38
        $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...
39
40
        if (strlen($summaryText) < self::SUMMARY_MIN_LENGTH) {
41
            throw new ContentException(sprintf("The summary text should not be shorter than %s characters", self::SUMMARY_MIN_LENGTH));
42
        }
43
44
        if (strlen($summaryText) > self::SUMMARY_MAX_LENGTH) {
45
            throw new ContentException(sprintf("The summary text should not be longer than %s characters", self::SUMMARY_MAX_LENGTH));
46
        }
47
48
        $this->summaryText = trim($summaryText);
49
        $this->productDescription = $productDescription;
50
    }
51
52
    /**
53
     * Get a short description text of the product (e.g. "The first edition of our fancy T-Shirt with a unicorn pooping
54
     * ice cream on the front")
55
     *
56
     * @return string
57
     */
58
    public function getSummaryText()
59
    {
60
        return $this->summaryText;
61
    }
62
63
    /**
64
     * Get a full product description text
65
     *
66
     * @return string
67
     */
68
    public function getProductDescription()
69
    {
70
        return $this->productDescription;
71
    }
72
}