Permissions   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 1
A allowNothing() 0 4 1
A allowEverything() 0 4 1
A toInt() 0 17 2
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
     * Creates permissions which allow nothing.
89
     *
90
     * @return self
91
     */
92
    public static function allowNothing()
93
    {
94
        return new self(false, false, false, false, false, false, false, false);
95
    }
96
97
    /**
98
     * Creates permissions which allow everything.
99
     *
100
     * @return self
101
     */
102
    public static function allowEverything()
103
    {
104
        return new self(true, true, true, true, true, true, true, true);
105
    }
106
107
    /**
108
     * Convert the permissions to am integer bit mask.
109
     *
110
     * {@internal Keep in mind that the bit positions named in the PDF reference are counted from 1, while in here they
111
     * are counted from 0.}}
112
     *
113
     * @param  int $revision
114
     * @return int
115
     */
116
    public function toInt($revision)
117
    {
118
        $bitMask = new BitMask();
119
        $bitMask->set(2, $this->mayPrint);
120
        $bitMask->set(3, $this->mayModify);
121
        $bitMask->set(4, $this->mayCopy);
122
        $bitMask->set(5, $this->mayAnnotate);
123
124
        if ($revision >= 3) {
125
            $bitMask->set(8, $this->mayFillInForms);
126
            $bitMask->set(9, $this->mayExtractForAccessibility);
127
            $bitMask->set(10, $this->mayAssemble);
128
            $bitMask->set(11, $this->mayPrintHighResolution);
129
        }
130
131
        return $bitMask->toInt();
132
    }
133
}
134