Completed
Push — master ( 146f46...ce721c )
by Thomas
03:30
created

CodeFileGeneratorConfig::getDefaultOptions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 1

Importance

Changes 5
Bugs 0 Features 1
Metric Value
c 5
b 0
f 1
dl 0
loc 15
ccs 13
cts 13
cp 1
rs 9.4285
cc 1
eloc 11
nc 1
nop 0
crap 1
1
<?php
2
namespace gossi\codegen\config;
3
4
use gossi\docblock\Docblock;
5
use Symfony\Component\OptionsResolver\Options;
6
7
class CodeFileGeneratorConfig extends CodeGeneratorConfig {
8
9 9
	protected function getOptionalOptions() {
10 9
		return array_merge([
11 9
				'headerComment', 'headerDocblock', 'blankLineAtEnd', 'declareStrictTypes'
12 9
			], parent::getOptionalOptions());
13
	}
14
15 9
	protected function getDefaultOptions() {
16 9
		return array_merge(
17 9
			parent::getDefaultOptions(), [
18 9
				'headerComment' => '',
19 9
				'headerDocblock' => null,
20 9
				'blankLineAtEnd' => true,
21 9
				'declareStrictTypes'  => false,
22
				'generateScalarTypeHints' => function (Options $options) {
23 9
					return $options['declareStrictTypes'];
24 9
				},
25 9
				'generateReturnTypeHints' => function (Options $options) {
26 9
					return $options['declareStrictTypes'];
27 9
				},
28 9
			]);
29
	}
30
31 9
	protected function getAllowedOptionTypes() {
32 9
		return array_merge([
33 9
				'headerComment' => 'string',
34 9
				'headerDocblock' => ['null', 'gossi\\docblock\\Docblock'],
35 9
				'blankLineAtEnd' => 'bool',
36 9
				'declareStrictTypes' => 'bool',
37 9
			], parent::getAllowedOptionTypes());
38
	}
39
40
	/**
41
	 * Returns the file header comment
42
	 * 
43
	 * @return string the header comment
44
	 */
45 8
	public function getHeaderComment() {
46 8
		return $this->options['headerComment'];
47
	}
48
49
	/**
50
	 * Sets the file header comment
51
	 * 
52
	 * @param string $comment the header comment
53
	 * @return $this
54
	 */
55 1
	public function setHeaderComment($comment) {
56 1
		$this->options['headerComment'] = $comment;
57 1
		return $this;
58
	}
59
60
	/**
61
	 * Returns the file header docblock
62
	 * 
63
	 * @return Docblock the docblock
64
	 */
65 8
	public function getHeaderDocblock() {
66 8
		return $this->options['headerDocblock'];
67
	}
68
69
	/**
70
	 * Sets the file header docblock
71
	 * 
72
	 * @param Docblock $docblock the docblock
73
	 * @return $this
74
	 */
75 1
	public function setHeaderDocblock(Docblock $docblock) {
76 1
		$this->options['headerDocblock'] = $docblock;
77 1
		return $this;
78
	}
79
80
	/**
81
	 * Returns whether a blank line should be generated at the end of the file
82
	 * 
83
	 * @return boolean `true` if it will be generated and `false` if not
84
	 */
85 8
	public function getBlankLineAtEnd() {
86 8
		return $this->options['blankLineAtEnd'];
87
	}
88
89
	/**
90
	 * Sets whether a blank line should be generated at the end of the file
91
	 * 
92
	 * @param boolean $show `true` if it will be generated and `false` if not
93
	 * @return $this
94
	 */
95 1
	public function setBlankLineAtEnd($show) {
96 1
		$this->options['blankLineAtEnd'] = $show;
97 1
		return $this;
98
	}
99
100
	/**
101
	 * Returns whether a `declare(strict_types=1);` statement should be printed 
102
	 * below the header comments (PHP 7)
103
	 * 
104
	 * @return boolean `true` if it will be printed and `false` if not
105
	 */
106 9
	public function getDeclareStrictTypes() {
107 9
		return $this->options['declareStrictTypes'];
108
	}
109
110
	/**
111
	 * Sets whether a `declare(strict_types=1);` statement should be printed 
112
	 * below the header comments (PHP 7)
113
	 * 
114
	 * @param boolean $strict `true` if it will be printed and `false` if not
115
	 * @return $this
116
	 */
117 1
	public function setDeclareStrictTypes($strict) {
118 1
		$this->options['declareStrictTypes'] = $strict;
119 1
		return $this;
120
	}
121
}
122