Completed
Pull Request — master (#7)
by Markus
06:25
created

IterateTask::setList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 32 and the first side effect is on line 16.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
// +---------------------------------------------------------------------------+
4
// | This file is part of the Agavi package.                                   |
5
// | Copyright (c) 2005-2011 the Agavi Project.                                |
6
// |                                                                           |
7
// | For the full copyright and license information, please view the LICENSE   |
8
// | file that was distributed with this source code. You can also view the    |
9
// | LICENSE file online at http://www.agavi.org/LICENSE.txt                   |
10
// |   vi: set noexpandtab:                                                    |
11
// |   Local Variables:                                                        |
12
// |   indent-tabs-mode: t                                                     |
13
// |   End:                                                                    |
14
// +---------------------------------------------------------------------------+
15
16
require_once(__DIR__ . '/AgaviTask.php');
17
18
/**
19
 * Iterates over a list, calling a target.
20
 *
21
 * @package    agavi
22
 * @subpackage build
23
 *
24
 * @author     Noah Fontes <[email protected]>
25
 * @copyright  Authors
26
 * @copyright  The Agavi Project
27
 *
28
 * @since      1.0.0
29
 *
30
 * @version    $Id$
31
 */
32
class IterateTask extends AgaviTask
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
33
{
34
	protected $property = null;
35
	protected $list = null;
36
	protected $target = null;
37
	protected $delimiter = ' ';
38
	protected $exceptionsFatal = true;
39
	
40
	/**
41
	 * Sets the property that this task will assign.
42
	 * 
43
	 * @param      string The property to assign.
44
	 */
45
	public function setProperty($property)
46
	{
47
		$this->property = $property;
48
	}
49
	
50
	/**
51
	 * Sets the list that this task will iterate.
52
	 *
53
	 * @param      string The list to iterate.
54
	 */
55
	public function setList($list)
56
	{
57
		$this->list = $list;
58
	}
59
	
60
	/**
61
	 * Sets the target that this task will call.
62
	 *
63
	 * @param      string The target name.
64
	 */
65
	public function setTarget($target)
66
	{
67
		$this->target = $target;
68
	}
69
	
70
	/**
71
	 * Sets the list delimiter character.
72
	 *
73
	 * @param      string The delimiter.
74
	 */
75
	public function setDelimiter($delimiter)
76
	{
77
		$this->delimiter = $delimiter;
78
	}
79
	
80
	/**
81
	 * Sets whether exceptions are fatal for targets called by this task.
82
	 *
83
	 * @param      bool Whether exceptions should be considered fatal.
84
	 */
85
	public function setExceptionsFatal($exceptionsFatal)
86
	{
87
		$this->exceptionsFatal = StringHelper::booleanValue($exceptionsFatal);
88
	}
89
	
90
	/**
91
	 * Executes this target.
92
	 */
93
	public function main()
94
	{
95
		if($this->property === null) {
96
			throw new BuildException('The property attribute must be specified');
97
		}
98
		if($this->list === null) {
99
			throw new BuildException('The list attribute must be specified');
100
		}
101
		if($this->target === null) {
102
			throw new BuildException('The target attribute must be specified');
103
		}
104
		
105
		$transform = new \Agavi\Build\Transform\StringtoarrayTransform();
106
		$transform->setInput($this->list);
107
		$transform->setDelimiter($this->delimiter);
108
		
109
		foreach($transform->transform() as $value) {
110
			$this->project->setUserProperty($this->property, $value);
111
			
112
			$task = $this->project->createTask('agavi.execute-target');
113
			$task->setName($this->target);
114
			$task->setExceptionsFatal($this->exceptionsFatal);
115
			$task->init();
116
			$task->main();
117
		}
118
	}
119
}
120
121
?>
0 ignored issues
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...