PasswordTrait::setPassword()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 1
eloc 3
c 1
b 1
f 1
nc 1
nop 1
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace Comodojo\Zip\Traits;
4
5
use \Comodojo\Zip\Interfaces\ZipInterface;
6
use \ZipArchive;
7
8
/**
9
 * Password helper trait.
10
 *
11
 * @package     Comodojo Zip
12
 * @author      Marco Giovinazzi <[email protected]>
13
 * @license     MIT
14
 *
15
 * LICENSE:
16
 *
17
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23
 * THE SOFTWARE.
24
 */
25
26
trait PasswordTrait
27
{
28
29
    abstract public function getArchive(): ?ZipArchive;
30
31
    /**
32
     * zip file password
33
     *
34
     * @var string
35
     */
36
    private ?string $password = null;
37
38
    /**
39
     * Set zip password
40
     *
41
     * @param string $password
42
     *
43
     * @return ZipInterface
44
     */
45 5
    public function setPassword(string $password): ZipInterface
46
    {
47 5
        $this->password = $password;
48 5
        $this->getArchive()->setPassword($password);
49
50 5
        return $this;
51
    }
52
53
    /**
54
     * Get current zip password
55
     *
56
     * @return string
57
     */
58 4
    protected function getPassword(): ?string
59
    {
60 4
        return $this->password;
61
    }
62
}
63