Convert_encoding   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 0
dl 0
loc 70
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A check_route() 0 9 3
A run() 0 21 5
A add_agent() 0 17 3
A convert_to_utf8() 0 16 2
1
<?php
2
3
class Convert_encoding
4
{
5
	private function check_route()
6
	{
7
		if (isset($_SERVER['PATH_INFO']) && substr($_SERVER['PATH_INFO'], 0, 4) === '/bbs')
8
		{
9
			return true;
10
		}
11
12
		return false;
13
	}
14
15
	public function run()
16
	{
17
		if (is_cli())
18
		{
19
			return;
20
		}
21
22
		if ( ! $this->check_route())
23
		{
24
			return;
25
		}
26
27
# 携帯端末からのアクセスを判定するためユーザエージェントクラスをロードします。
28
		$agent =& load_class('User_agent');
29
30
# 携帯端末からの入力文字エンコードを変換します。
31
		if (count($_POST) > 1 && $agent->is_mobile())
32
		{
33
			$_POST = $this->convert_to_utf8($_POST);
34
		}
35
	}
36
37
	public function add_agent()
38
	{
39
		if (is_cli())
40
		{
41
			return;
42
		}
43
44
		if (! $this->check_route()) {
45
			return;
46
		}
47
48
		// load_class()でuser_agentをロードしたため、$this->user_agentとして
49
		// して代入されているので、それを$this->agentに変更する
50
		$CI =& get_instance();
51
		$CI->agent = $CI->user_agent;
0 ignored issues
show
Bug introduced by
The property agent does not seem to exist in CI_Controller.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
Bug introduced by
The property user_agent does not seem to exist in CI_Controller.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
52
		unset($CI->user_agent);
53
	}
54
55
	// 入力文字エンコード変換
56
	private function convert_to_utf8($array)
57
	{
58
# 引数が配列の場合は、配列の各々の要素を自分自身に渡し処理します。
59
# array_map()関数の第1引数は、コールバック関数ですが、ここでは、クラス内の
60
# メソッドを指定しますので、[$this, 'convert_to_utf8']と配列
61
# で渡す必要があります。
62
		if (is_array($array))
63
		{
64
			return array_map([$this, 'convert_to_utf8'], $array);
65
		}
66
# 引数が配列でない場合は、文字エンコードをUTF-8に変換し、返します。
67
		else
68
		{
69
			return mb_convert_encoding($array, 'UTF-8', 'SJIS-win');
70
		}
71
	}
72
}
73