Shop_model   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 58
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A order() 0 45 3
1
<?php
2
3
/**
4
 * @property Cart_model     $cart_model
5
 * @property Customer_model $customer_model
6
 * @property Mail_model     $mail_model
7
 */
8
class Shop_model extends CI_Model {
9
10
	public function __construct()
11
	{
12
		parent::__construct();
13
		$this->load->model('shop/cart_model');
0 ignored issues
show
Documentation introduced by
The property load does not exist on object<Shop_model>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
14
		$this->load->model('shop/customer_model');
0 ignored issues
show
Documentation introduced by
The property load does not exist on object<Shop_model>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
15
		$this->load->model('shop/mail_model');
0 ignored issues
show
Documentation introduced by
The property load does not exist on object<Shop_model>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
16
	}
17
18
	// 注文の処理
19
	public function order()
20
	{
21
		$data = [];
22
# 注文日時をPHPのdate()関数から取得します。
23
		$data['date'] = date("Y/m/d H:i:s");
24
# カートの情報を取得します。
25
		$cart = $this->cart_model->get_all();
26
		foreach ($cart['items'] as &$item)
27
		{
28
			$item['price']  = number_format($item['price']);
29
			$item['amount'] = number_format($item['amount']);
30
		}
31
		$data['items']  = $cart['items'];
32
		$data['line']  = $cart['line'];
33
		$data['total'] = number_format($cart['total']);
34
35
# お客様情報を取得します。
36
		$data = array_merge($data, $this->customer_model->get());
37
38
# メールのヘッダを設定します。Bccで同じメールを管理者にも送るようにします。
39
		$mail = [];
40
		$mail['from_name'] = 'CIショップ';
41
		$mail['from']      = $this->admin;
0 ignored issues
show
Bug introduced by
The property admin does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
42
		$mail['to']        = $data['email'];
43
		$mail['bcc']       = $this->admin;
44
		$mail['subject']   = '【注文メール】CIショップ';
45
46
# テンプレートパーサクラスでメール本文を作成します。
47
		$this->load->library('parser');
0 ignored issues
show
Documentation introduced by
The property load does not exist on object<Shop_model>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
48
		$mail['body'] = $this->parser->parse(
0 ignored issues
show
Documentation introduced by
The property parser does not exist on object<Shop_model>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
49
			'templates/mail/shop_order', $data, TRUE
50
		);
51
52
# sendmail()メソッドを呼び出し、実際にメールを送信します。メール送信に成功
53
# すれば、TRUEを返します。
54
		if ($this->mail_model->sendmail($mail))
55
		{
56
			return TRUE;
57
		}
58
# メール送信に失敗した場合は、FALSEを返します。
59
		else
60
		{
61
			return FALSE;
62
		}
63
	}
64
65
}
66