Completed
Push — develop ( f11aab...a4697b )
by Alejandro
09:31
created

AttachmentsOptions::getFiles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 0
ccs 2
cts 2
cp 1
crap 1
1
<?php
2
namespace AcMailer\Options;
3
4
use Zend\Stdlib\AbstractOptions;
5
6
/**
7
 * Class AttachmentsOptions
8
 * @author Alejandro Celaya Alstrué
9
 * @link http://www.alejandrocelaya.com
10
 */
11
class AttachmentsOptions extends AbstractOptions
12
{
13
    const DEFAULT_ITERATE   = false;
14
    const DEFAULT_PATH      = 'data/mail/attachments';
15
    const DEFAULT_RECURSIVE = false;
16
17
    /**
18
     * @var array
19
     */
20
    private $files = [];
21
    /**
22
     * @var array
23
     */
24
    private $dir = [
25
        'iterate'   => self::DEFAULT_ITERATE,
26
        'path'      => self::DEFAULT_PATH,
27
        'recursive' => self::DEFAULT_RECURSIVE,
28
    ];
29
30
    /**
31
     * @param array $dir
32
     * @return $this
33
     */
34 3
    public function setDir($dir)
35
    {
36 3
        $this->dir = $dir;
37 3
        return $this->normalizeDirArray();
38
    }
39
    /**
40
     * @return array
41
     */
42 14
    public function getDir()
43
    {
44 14
        return $this->dir;
45
    }
46
47
    /**
48
     * @param array $files
49
     * @return $this
50
     */
51 2
    public function setFiles(array $files)
52
    {
53 2
        $this->files = $files;
54 2
        return $this;
55
    }
56
    /**
57
     * @return array
58
     */
59 13
    public function getFiles()
60
    {
61 13
        return $this->files;
62
    }
63
    /**
64
     * @param $filePath
65
     * @return $this
66
     */
67 1
    public function addFile($filePath)
68
    {
69 1
        $this->files[] = $filePath;
70 1
        return $this;
71
    }
72
    /**
73
     * @param array $files
74
     * @return $this
75
     */
76 1
    public function addFiles(array $files)
77
    {
78 1
        return $this->setFiles(array_merge($this->files, $files));
79
    }
80
81
    /**
82
     * Makes sure dir array has default properties at least
83
     * @return $this
84
     */
85 3
    protected function normalizeDirArray()
86
    {
87 3
        if (! isset($this->dir['iterate'])) {
88 2
            $this->dir['iterate'] = self::DEFAULT_ITERATE;
89 2
        }
90 3
        if (! isset($this->dir['path'])) {
91 2
            $this->dir['path'] = self::DEFAULT_PATH;
92 2
        }
93 3
        if (! isset($this->dir['recursive'])) {
94 1
            $this->dir['recursive'] = self::DEFAULT_RECURSIVE;
95 1
        }
96
97 3
        return $this;
98
    }
99
}
100