Passed
Push — master ( 6bc86c...f6271c )
by Aimeos
13:16 queued 14s
created

Standard::getCustomer()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 2
dl 0
loc 12
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2023
6
 * @package Client
7
 * @subpackage Html
8
 */
9
10
11
namespace Aimeos\Client\Html\Checkout\Standard\Process\Account;
12
13
14
/**
15
 * Default implementation of checkout process account HTML client
16
 *
17
 * @package Client
18
 * @subpackage Html
19
 */
20
class Standard
21
	extends \Aimeos\Client\Html\Common\Client\Factory\Base
22
	implements \Aimeos\Client\Html\Common\Client\Factory\Iface
23
{
24
	/**
25
	 * Returns the HTML code for insertion into the body.
26
	 *
27
	 * @param string $uid Unique identifier for the output if the content is placed more than once on the same page
28
	 * @return string HTML code
29
	 */
30
	public function body( string $uid = '' ) : string
31
	{
32
		return '';
33
	}
34
35
36
	/**
37
	 * Processes the input, e.g. provides the account form.
38
	 *
39
	 * A view must be available and this method doesn't generate any output
40
	 * besides setting view variables.
41
	 */
42
	public function init()
43
	{
44
		$context = $this->context();
45
46
		try
47
		{
48
			$type = \Aimeos\MShop\Order\Item\Address\Base::TYPE_PAYMENT;
49
			$addresses = \Aimeos\Controller\Frontend::create( $context, 'basket' )->get()->getAddress( $type );
50
51
			if( $context->user() === null && ( $address = current( $addresses ) ) !== false )
52
			{
53
				$create = (bool) $this->view()->param( 'cs_option_account' );
54
				$context->setUser( $this->getCustomer( $address, $create ) );
55
			}
56
		}
57
		catch( \Exception $e )
58
		{
59
			$msg = sprintf( 'Unable to create an account: %1$s', $e->getMessage() );
60
			$context->logger()->notice( $msg, 'client/html' );
61
		}
62
63
		parent::init();
64
	}
65
66
67
	/**
68
	 * Creates a new account (if necessary) and returns its customer ID
69
	 *
70
	 * @param \Aimeos\MShop\Common\Item\Address\Iface $addr Address object from order
71
	 * @param bool $new True to create the customer if it doesn't exist, false if not
72
	 * @return \Aimeos\MShop\Customer\Item\\Iface|null Unique customer ID or null if no customer is available
0 ignored issues
show
Bug introduced by
The type Aimeos\MShop\Customer\Item\\Iface 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...
73
	 */
74
	protected function getCustomer( \Aimeos\MShop\Common\Item\Address\Iface $addr, bool $new ) : ?\Aimeos\MShop\Customer\Item\Iface
75
	{
76
		$context = $this->context();
77
		$cntl = \Aimeos\Controller\Frontend::create( $context, 'customer' );
78
79
		try {
80
			$customer = $cntl->find( $addr->getEmail() );
81
		} catch( \Exception $e ) {
82
			$customer = $new ? $cntl->add( $addr->toArray() )->store()->get() : null;
83
		}
84
85
		return $customer;
86
	}
87
}
88