PasswordTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 1 Features 1
Metric Value
eloc 5
c 1
b 1
f 1
dl 0
loc 35
ccs 6
cts 6
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setPassword() 0 6 1
A getPassword() 0 3 1
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