Completed
Push — master ( a3489b...087532 )
by Mark
33s queued 30s
created

Axis::setAxisOptionsProperties()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 15
c 0
b 0
f 0
dl 0
loc 32
ccs 16
cts 16
cp 1
rs 9.7666
cc 1
nc 1
nop 15
crap 1

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
namespace PhpOffice\PhpSpreadsheet\Chart;
4
5
/**
6
 * Created by PhpStorm.
7
 * User: Wiktor Trzonkowski
8
 * Date: 6/17/14
9
 * Time: 12:11 PM.
10
 */
11
class Axis extends Properties
12
{
13
    const AXIS_TYPE_CATEGORY = 'catAx';
14
    const AXIS_TYPE_DATE = 'dateAx';
15
    const AXIS_TYPE_VALUE = 'valAx';
16
17
    const TIME_UNIT_DAYS = 'days';
18
    const TIME_UNIT_MONTHS = 'months';
19
    const TIME_UNIT_YEARS = 'years';
20
21 91
    public function __construct()
22
    {
23 91
        parent::__construct();
24 91
        $this->fillColor = new ChartColor();
25
    }
26
27
    /**
28
     * Chart Major Gridlines as.
29
     *
30
     * @var ?GridLines
31
     */
32
    private $majorGridlines;
33
34
    /**
35
     * Chart Minor Gridlines as.
36
     *
37
     * @var ?GridLines
38
     */
39
    private $minorGridlines;
40
41
    /**
42
     * Axis Number.
43
     *
44
     * @var mixed[]
45
     */
46
    private $axisNumber = [
47
        'format' => self::FORMAT_CODE_GENERAL,
48
        'source_linked' => 1,
49
        'numeric' => null,
50
    ];
51
52
    /** @var string */
53
    private $axisType = '';
54
55
    /** @var ?AxisText */
56
    private $axisText;
57
58
    /**
59
     * Axis Options.
60
     *
61
     * @var mixed[]
62
     */
63
    private $axisOptions = [
64
        'minimum' => null,
65
        'maximum' => null,
66
        'major_unit' => null,
67
        'minor_unit' => null,
68
        'orientation' => self::ORIENTATION_NORMAL,
69
        'minor_tick_mark' => self::TICK_MARK_NONE,
70
        'major_tick_mark' => self::TICK_MARK_NONE,
71
        'axis_labels' => self::AXIS_LABELS_NEXT_TO,
72
        'horizontal_crosses' => self::HORIZONTAL_CROSSES_AUTOZERO,
73
        'horizontal_crosses_value' => null,
74
        'textRotation' => null,
75
        'hidden' => null,
76
        'majorTimeUnit' => self::TIME_UNIT_YEARS,
77
        'minorTimeUnit' => self::TIME_UNIT_MONTHS,
78
        'baseTimeUnit' => self::TIME_UNIT_DAYS,
79
    ];
80
81
    /**
82
     * Fill Properties.
83
     *
84
     * @var ChartColor
85
     */
86
    private $fillColor;
87
88
    private const NUMERIC_FORMAT = [
89
        Properties::FORMAT_CODE_NUMBER,
90
        Properties::FORMAT_CODE_DATE,
91
        Properties::FORMAT_CODE_DATE_ISO8601,
92
    ];
93
94
    /**
95
     * Get Series Data Type.
96
     *
97
     * @param mixed $format_code
98
     */
99 56
    public function setAxisNumberProperties($format_code, ?bool $numeric = null, int $sourceLinked = 0): void
100
    {
101 56
        $format = (string) $format_code;
102 56
        $this->axisNumber['format'] = $format;
103 56
        $this->axisNumber['source_linked'] = $sourceLinked;
104 56
        if (is_bool($numeric)) {
105 8
            $this->axisNumber['numeric'] = $numeric;
106 52
        } elseif (in_array($format, self::NUMERIC_FORMAT, true)) {
107 7
            $this->axisNumber['numeric'] = true;
108
        }
109
    }
110
111
    /**
112
     * Get Axis Number Format Data Type.
113
     *
114
     * @return string
115
     */
116 70
    public function getAxisNumberFormat()
117
    {
118 70
        return $this->axisNumber['format'];
119
    }
120
121
    /**
122
     * Get Axis Number Source Linked.
123
     *
124
     * @return string
125
     */
126 70
    public function getAxisNumberSourceLinked()
127
    {
128 70
        return (string) $this->axisNumber['source_linked'];
129
    }
130
131 42
    public function getAxisIsNumericFormat(): bool
132
    {
133 42
        return $this->axisType === self::AXIS_TYPE_DATE || (bool) $this->axisNumber['numeric'];
134
    }
135
136 54
    public function setAxisOption(string $key, ?string $value): void
137
    {
138 54
        if ($value !== null && $value !== '') {
139 53
            $this->axisOptions[$key] = $value;
140
        }
141
    }
142
143
    /**
144
     * Set Axis Options Properties.
145
     */
146 4
    public function setAxisOptionsProperties(
147
        string $axisLabels,
148
        ?string $horizontalCrossesValue = null,
149
        ?string $horizontalCrosses = null,
150
        ?string $axisOrientation = null,
151
        ?string $majorTmt = null,
152
        ?string $minorTmt = null,
153
        ?string $minimum = null,
154
        ?string $maximum = null,
155
        ?string $majorUnit = null,
156
        ?string $minorUnit = null,
157
        ?string $textRotation = null,
158
        ?string $hidden = null,
159
        ?string $baseTimeUnit = null,
160
        ?string $majorTimeUnit = null,
161
        ?string $minorTimeUnit = null
162
    ): void {
163 4
        $this->axisOptions['axis_labels'] = $axisLabels;
164 4
        $this->setAxisOption('horizontal_crosses_value', $horizontalCrossesValue);
165 4
        $this->setAxisOption('horizontal_crosses', $horizontalCrosses);
166 4
        $this->setAxisOption('orientation', $axisOrientation);
167 4
        $this->setAxisOption('major_tick_mark', $majorTmt);
168 4
        $this->setAxisOption('minor_tick_mark', $minorTmt);
169 4
        $this->setAxisOption('minimum', $minimum);
170 4
        $this->setAxisOption('maximum', $maximum);
171 4
        $this->setAxisOption('major_unit', $majorUnit);
172 4
        $this->setAxisOption('minor_unit', $minorUnit);
173 4
        $this->setAxisOption('textRotation', $textRotation);
174 4
        $this->setAxisOption('hidden', $hidden);
175 4
        $this->setAxisOption('baseTimeUnit', $baseTimeUnit);
176 4
        $this->setAxisOption('majorTimeUnit', $majorTimeUnit);
177 4
        $this->setAxisOption('minorTimeUnit', $minorTimeUnit);
178
    }
179
180
    /**
181
     * Get Axis Options Property.
182
     *
183
     * @param string $property
184
     *
185
     * @return ?string
186
     */
187 70
    public function getAxisOptionsProperty($property)
188
    {
189 70
        if ($property === 'textRotation') {
190 70
            if ($this->axisText !== null) {
191 6
                if ($this->axisText->getRotation() !== null) {
192 6
                    return (string) $this->axisText->getRotation();
193
                }
194
            }
195
        }
196
197 70
        return $this->axisOptions[$property];
198
    }
199
200
    /**
201
     * Set Axis Orientation Property.
202
     *
203
     * @param string $orientation
204
     */
205 1
    public function setAxisOrientation($orientation): void
206
    {
207 1
        $this->axisOptions['orientation'] = (string) $orientation;
208
    }
209
210 69
    public function getAxisType(): string
211
    {
212 69
        return $this->axisType;
213
    }
214
215 52
    public function setAxisType(string $type): self
216
    {
217 52
        if ($type === self::AXIS_TYPE_CATEGORY || $type === self::AXIS_TYPE_VALUE || $type === self::AXIS_TYPE_DATE) {
218 52
            $this->axisType = $type;
219
        } else {
220 3
            $this->axisType = '';
221
        }
222
223 52
        return $this;
224
    }
225
226
    /**
227
     * Set Fill Property.
228
     *
229
     * @param ?string $color
230
     * @param ?int $alpha
231
     * @param ?string $AlphaType
232
     */
233 4
    public function setFillParameters($color, $alpha = null, $AlphaType = ChartColor::EXCEL_COLOR_TYPE_RGB): void
234
    {
235 4
        $this->fillColor->setColorProperties($color, $alpha, $AlphaType);
236
    }
237
238
    /**
239
     * Get Fill Property.
240
     *
241
     * @param string $property
242
     *
243
     * @return string
244
     */
245 1
    public function getFillProperty($property)
246
    {
247 1
        return (string) $this->fillColor->getColorProperty($property);
248
    }
249
250 70
    public function getFillColorObject(): ChartColor
251
    {
252 70
        return $this->fillColor;
253
    }
254
255
    /**
256
     * Get Line Color Property.
257
     *
258
     * @deprecated 1.24.0
259
     *      Use the getLineColor property in the Properties class instead
260
     * @see Properties::getLineColorProperty()
261
     *
262
     * @param string $propertyName
263
     *
264
     * @return null|int|string
265
     */
266
    public function getLineProperty($propertyName)
267
    {
268
        return $this->getLineColorProperty($propertyName);
269
    }
270
271
    /** @var string */
272
    private $crossBetween = ''; // 'between' or 'midCat' might be better
273
274 35
    public function setCrossBetween(string $crossBetween): self
275
    {
276 35
        $this->crossBetween = $crossBetween;
277
278 35
        return $this;
279
    }
280
281 70
    public function getCrossBetween(): string
282
    {
283 70
        return $this->crossBetween;
284
    }
285
286 70
    public function getMajorGridlines(): ?GridLines
287
    {
288 70
        return $this->majorGridlines;
289
    }
290
291 70
    public function getMinorGridlines(): ?GridLines
292
    {
293 70
        return $this->minorGridlines;
294
    }
295
296 40
    public function setMajorGridlines(?GridLines $gridlines): self
297
    {
298 40
        $this->majorGridlines = $gridlines;
299
300 40
        return $this;
301
    }
302
303 10
    public function setMinorGridlines(?GridLines $gridlines): self
304
    {
305 10
        $this->minorGridlines = $gridlines;
306
307 10
        return $this;
308
    }
309
310 70
    public function getAxisText(): ?AxisText
311
    {
312 70
        return $this->axisText;
313
    }
314
315 10
    public function setAxisText(?AxisText $axisText): self
316
    {
317 10
        $this->axisText = $axisText;
318
319 10
        return $this;
320
    }
321
}
322