Standard   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
eloc 20
c 1
b 0
f 0
dl 0
loc 81
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 4 1
A get() 0 7 2
A start() 0 10 2
A transform() 0 3 1
A stop() 0 8 2
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2025
6
 * @package Base
7
 * @subpackage View
8
 */
9
10
11
namespace Aimeos\Base\View\Helper\Block;
12
13
use \Aimeos\Base\View\Exception;
0 ignored issues
show
Bug introduced by
The type \Aimeos\Base\View\Exception was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
15
16
/**
17
 * View helper class for handling template blocks
18
 *
19
 * @package Base
20
 * @subpackage View
21
 */
22
class Standard
23
	extends \Aimeos\Base\View\Helper\Base
24
	implements \Aimeos\Base\View\Helper\Block\Iface
25
{
26
	private array $blocks = [];
27
	private array $stack = [];
28
29
30
	/**
31
	 * Returns the block helper
32
	 *
33
	 * @return \Aimeos\Base\View\Helper\Block\Iface Block object
34
	 */
35
	public function transform() : Iface
36
	{
37
		return $this;
38
	}
39
40
41
	/**
42
	 * Returns the content block for the given name
43
	 *
44
	 * @param string $name Name of the block
45
	 * @return string|null Content of the block
46
	 */
47
	public function get( string $name ) : ?string
48
	{
49
		if( isset( $this->blocks[$name] ) ) {
50
			return $this->blocks[$name];
51
		}
52
53
		return null;
54
	}
55
56
57
	/**
58
	 * Sets the content of a block for the given name
59
	 *
60
	 * @param string $name Name of the block
61
	 * @param string $content Block content
62
	 * @return \Aimeos\Base\View\Helper\Block\Iface Block object for fluent interface
63
	 */
64
	public function set( string $name, string $content ) : Iface
65
	{
66
		$this->blocks[$name] = $content;
67
		return $this;
68
	}
69
70
71
	/**
72
	 * Starts a new content block
73
	 *
74
	 * @param string $name Name of the block
75
	 * @return \Aimeos\Base\View\Helper\Block\Iface Block object for fluent interface
76
	 */
77
	public function start( string $name ) : Iface
78
	{
79
		if( in_array( $name, $this->stack ) ) {
80
			throw new Exception( sprintf( 'Block "%1$s" has already been started', $name ) );
81
		}
82
83
		$this->stack[] = $name;
84
		ob_start();
85
86
		return $this;
87
	}
88
89
90
	/**
91
	 * Stores the current content block
92
	 *
93
	 * @return \Aimeos\Base\View\Helper\Block\Iface Block object for fluent interface
94
	 */
95
	public function stop() : Iface
96
	{
97
		if( ( $name = array_pop( $this->stack ) ) === null ) {
98
			throw new Exception( sprintf( 'No block has been started before' ) );
99
		}
100
101
		$this->blocks[$name] = ob_get_clean();
102
		return $this;
103
	}
104
}
105