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

GeneratorStrategy::setMethodSortFunc()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
/*
3
 * Copyright 2011 Johannes M. Schmitt <[email protected]>
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
namespace gossi\codegen\generator;
18
19
use gossi\codegen\model\GenerateableInterface;
20
use gossi\codegen\visitor\GeneratorNavigator;
21
use gossi\codegen\visitor\GeneratorVisitor;
22
use gossi\codegen\visitor\GeneratorVisitorInterface;
23
24
/**
25
 * The default generator strategy.
26
 *
27
 * This strategy allows to change the order in which methods, properties and
28
 * constants are sorted.
29
 *
30
 * @author Johannes M. Schmitt <[email protected]>
31
 */
32
class GeneratorStrategy {
33
34
	private $navigator;
35
36
	private $visitor;
37
38 18
	public function __construct(GeneratorVisitorInterface $visitor = null) {
39 18
		$this->navigator = new GeneratorNavigator();
40 18
		$this->visitor = $visitor ?: new GeneratorVisitor();
41 18
	}
42
43 2
	public function setConstantSortFunc(\Closure $func = null) {
44 2
		$this->navigator->setConstantSortFunc($func);
45 2
	}
46
47 2
	public function setMethodSortFunc(\Closure $func = null) {
48 2
		$this->navigator->setMethodSortFunc($func);
49 2
	}
50
51 2
	public function setPropertySortFunc(\Closure $func = null) {
52 2
		$this->navigator->setPropertySortFunc($func);
53 2
	}
54
55
	public function setUseStatementSortFunc(\Closure $func = null) {
56
		$this->navigator->setUseStatementSortFunc($func);
57
	}
58
59 18
	public function generate(GenerateableInterface $class) {
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
60 18
		$this->visitor->reset();
61 18
		$this->navigator->accept($this->visitor, $class);
62
63 18
		return $this->visitor->getContent();
64
	}
65
}
66