Exceptions   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 142
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 68
c 1
b 0
f 0
dl 0
loc 142
rs 10
wmc 21

3 Methods

Rating   Name   Duplication   Size   Complexity  
B body() 0 41 7
B init() 0 37 7
B header() 0 41 7
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2022-2025
6
 * @package Client
7
 * @subpackage Html
8
 */
9
10
11
namespace Aimeos\Client\Html\Common\Decorator;
12
13
14
/**
15
 * Provides exception handling for HTML clients.
16
 *
17
 * @package Client
18
 * @subpackage Html
19
 */
20
class Exceptions extends Base implements Iface
21
{
22
	/**
23
	 * Returns the HTML code for insertion into the body.
24
	 *
25
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
26
	 * @return string HTML code
27
	 */
28
	public function body( string $uid = '' ) : string
29
	{
30
		$output = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $output is dead and can be removed.
Loading history...
31
		$view = $this->view();
32
		$context = $this->context();
33
34
		try
35
		{
36
			$output = $this->client()->body( $uid );
37
		}
38
		catch( \Aimeos\Client\Html\Exception $e )
39
		{
40
			$error = [$context->translate( 'client', $e->getMessage() )];
41
			$view->errors = array_merge( $view->get( 'errors', [] ), $error );
42
		}
43
		catch( \Aimeos\Controller\Frontend\Exception $e )
44
		{
45
			if( $e->getCode() >= 400 ) {
46
				throw $e;
47
			}
48
49
			$error = [$context->translate( 'controller/frontend', $e->getMessage() )];
50
			$view->errors = array_merge( $view->get( 'errors', [] ), $error );
51
		}
52
		catch( \Aimeos\MShop\Exception $e )
53
		{
54
			if( $e->getCode() >= 400 ) {
55
				throw $e;
56
			}
57
58
			$error = [$context->translate( 'mshop', $e->getMessage() )];
59
			$view->errors = array_merge( $view->get( 'errors', [] ), $error );
60
		}
61
		catch( \Exception $e )
62
		{
63
			$error = [$context->translate( 'client', 'A non-recoverable error occured' )];
64
			$view->errors = array_merge( $view->get( 'errors', [] ), $error );
65
			$this->logException( $e );
66
		}
67
68
		return $view->render( 'error' ) . $output;
69
	}
70
71
72
	/**
73
	 * Returns the HTML string for insertion into the header.
74
	 *
75
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
76
	 * @return string|null String including HTML tags for the header on error
77
	 */
78
	public function header( string $uid = '' ) : ?string
79
	{
80
		$output = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $output is dead and can be removed.
Loading history...
81
		$view = $this->view();
82
		$context = $this->context();
83
84
		try
85
		{
86
			$output = $this->client()->header( $uid );
87
		}
88
		catch( \Aimeos\Client\Html\Exception $e )
89
		{
90
			$error = [$context->translate( 'client', $e->getMessage() )];
91
			$view->errors = array_merge( $view->get( 'errors', [] ), $error );
92
		}
93
		catch( \Aimeos\Controller\Frontend\Exception $e )
94
		{
95
			if( $e->getCode() >= 400 ) {
96
				throw $e;
97
			}
98
99
			$error = [$context->translate( 'controller/frontend', $e->getMessage() )];
100
			$view->errors = array_merge( $view->get( 'errors', [] ), $error );
101
		}
102
		catch( \Aimeos\MShop\Exception $e )
103
		{
104
			if( $e->getCode() >= 400 ) {
105
				throw $e;
106
			}
107
108
			$error = [$context->translate( 'mshop', $e->getMessage() )];
109
			$view->errors = array_merge( $view->get( 'errors', [] ), $error );
110
		}
111
		catch( \Exception $e )
112
		{
113
			$error = [$context->translate( 'client', 'A non-recoverable error occured' )];
114
			$view->errors = array_merge( $view->get( 'errors', [] ), $error );
115
			$this->logException( $e );
116
		}
117
118
		return $view->render( 'error' ) . $output;
119
	}
120
121
122
	/**
123
	 * Processes the input, e.g. store given values.
124
	 */
125
	public function init()
126
	{
127
		$view = $this->view();
128
		$context = $this->context();
129
130
		try
131
		{
132
			$this->client()->init();
133
		}
134
		catch( \Aimeos\Client\Html\Exception $e )
135
		{
136
			$error = array( $context->translate( 'client', $e->getMessage() ) );
137
			$view->errors = array_merge( $view->get( 'errors', [] ), $error );
138
		}
139
		catch( \Aimeos\Controller\Frontend\Exception $e )
140
		{
141
			if( $e->getCode() >= 400 ) {
142
				throw $e;
143
			}
144
145
			$error = array( $context->translate( 'controller/frontend', $e->getMessage() ) );
146
			$view->errors = array_merge( $view->get( 'errors', [] ), $error );
147
		}
148
		catch( \Aimeos\MShop\Exception $e )
149
		{
150
			if( $e->getCode() >= 400 ) {
151
				throw $e;
152
			}
153
154
			$error = array( $context->translate( 'mshop', $e->getMessage() ) );
155
			$view->errors = array_merge( $view->get( 'errors', [] ), $error );
156
		}
157
		catch( \Exception $e )
158
		{
159
			$error = array( $context->translate( 'client', 'A non-recoverable error occured' ) );
160
			$view->errors = array_merge( $view->get( 'errors', [] ), $error );
161
			$this->logException( $e );
162
		}
163
	}
164
}
165