Completed
Push — master ( bc5c42...47bad9 )
by Ben
02:53
created

Permissions::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 19
rs 9.4286
cc 1
eloc 17
nc 1
nop 8

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
 * BaconPdf
4
 *
5
 * @link      http://github.com/Bacon/BaconPdf For the canonical source repository
6
 * @copyright 2015 Ben Scholzen (DASPRiD)
7
 * @license   http://opensource.org/licenses/BSD-2-Clause Simplified BSD License
8
 */
9
10
namespace Bacon\Pdf\Encryption;
11
12
/**
13
 * Permissions as defined in table 3.20 in section 3.5
14
 */
15
final class Permissions
16
{
17
    /**
18
     * @var bool
19
     */
20
    private $mayPrint;
21
22
    /**
23
     * @var bool
24
     */
25
    private $mayPrintHighResolution;
26
27
    /**
28
     * @var bool
29
     */
30
    private $mayModify;
31
32
    /**
33
     * @var bool
34
     */
35
    private $mayCopy;
36
37
    /**
38
     * @var bool
39
     */
40
    private $mayAnnotate;
41
42
    /**
43
     * @var bool
44
     */
45
    private $mayFillInForms;
46
47
    /**
48
     * @var bool
49
     */
50
    private $mayExtractForAccessibility;
51
52
    /**
53
     * @var bool
54
     */
55
    private $mayAssemble;
56
57
    /**
58
     * @param bool $mayPrint
59
     * @param bool $mayPrintHighResolution
60
     * @param bool $mayModify
61
     * @param bool $mayCopy
62
     * @param bool $mayAnnotate
63
     * @param bool $mayFillInForms
64
     * @param bool $mayExtractForAccessibility
65
     * @param bool $mayAssemble
66
     */
67
    public function __construct(
68
        $mayPrint,
69
        $mayPrintHighResolution,
70
        $mayModify,
71
        $mayCopy,
72
        $mayAnnotate,
73
        $mayFillInForms,
74
        $mayExtractForAccessibility,
75
        $mayAssemble
76
    ) {
77
        $this->mayPrint                   = $mayPrint;
78
        $this->mayPrintHighResolution     = $mayPrintHighResolution;
79
        $this->mayModify                  = $mayModify;
80
        $this->mayCopy                    = $mayCopy;
81
        $this->mayAnnotate                = $mayAnnotate;
82
        $this->mayFillInForms             = $mayFillInForms;
83
        $this->mayExtractForAccessibility = $mayExtractForAccessibility;
84
        $this->mayAssemble                = $mayAssemble;
85
    }
86
87
    /**
88
     * @param  int $revision
89
     * @return int
90
     */
91
    public function toInt($revision)
92
    {
93
        $flags = 0;
94
95
        if ($this->mayPrint) {
96
            $flags |= 3;
97
        }
98
99
        if ($this->mayModify) {
100
            $flags |= 4;
101
        }
102
103
        if ($this->mayCopy) {
104
            $flags |= 5;
105
        }
106
107
        if ($this->mayAnnotate) {
108
            $flags |= 6;
109
        }
110
111
        if ($revision >= 3) {
112
            if ($this->mayFillInForms) {
113
                $flags |= 9;
114
            }
115
116
            if ($this->mayExtractForAccessibility) {
117
                $flags |= 10;
118
            }
119
120
            if ($this->mayAssemble) {
121
                $flags |= 11;
122
            }
123
124
            if ($this->mayPrintHighResolution) {
125
                $flags |= 12;
126
            }
127
        }
128
129
        return $flags;
130
    }
131
}
132