Book::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 13
nc 1
nop 12

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace AntoineAugusti\Books;
4
5
use DateTime;
6
7
class Book
8
{
9
    public $title;
10
    public $subtitle;
11
    public $authors;
12
    public $printType;
13
    public $pageCount;
14
    public $publisher;
15
    public $publishedDate;
16
    public $publishedDateFormat;
17
    public $averageRating;
18
    public $thumbnail;
19
    public $language;
20
    public $categories;
21
22
    /**
23
     * New up a book.
24
     *
25
     * @param string   $title
26
     * @param string   $subtitle
27
     * @param array    $authors
28
     * @param string   $printType
29
     * @param int      $pageCount
30
     * @param string   $publisher
31
     * @param DateTime $publishedDate
32
     * @param int      $averageRating
33
     * @param string   $thumbnail
34
     * @param string   $language
35
     * @param array    $categories
36
     */
37
    public function __construct($title, $subtitle, array $authors, $printType, $pageCount, $publisher, DateTime $publishedDate = null, $publishedDateFormat, $averageRating, $thumbnail, $language, array $categories)
38
    {
39
        $this->title = $title;
40
        $this->subtitle = $subtitle;
41
        $this->authors = $authors;
42
        $this->printType = $printType;
43
        $this->pageCount = $pageCount;
44
        $this->publisher = $publisher;
45
        $this->publishedDate = $publishedDate;
46
        $this->publishedDateFormat = $publishedDateFormat;
47
        $this->averageRating = $averageRating;
48
        $this->thumbnail = $thumbnail;
49
        $this->language = $language;
50
        $this->categories = $categories;
51
    }
52
}
53