Kohana_Jam_Behavior_Username   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 18.18%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 28
ccs 2
cts 11
cp 0.1818
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initialize() 0 19 1
A username_key() 0 4 4
1
<?php defined('SYSPATH') OR die('No direct access allowed.');
2
/**
3
 * @package    Jam
4
 * @category   Behavior
5
 * @author     Ivan Kerin
6
 * @copyright  (c) 2011-2012 Despark Ltd.
7
 * @license    http://www.opensource.org/licenses/isc-license.txt
8
 */
9
class Kohana_Jam_Behavior_Username extends Jam_Behavior {
10
11
	public function initialize(Jam_Meta $meta, $name)
12
	{
13
		parent::initialize($meta, $name);
14
15
		$meta
0 ignored issues
show
Bug introduced by
The method name_key cannot be called on $meta->unique_key(array($this, 'username_key')) (of type string).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
16
			->unique_key(array($this, 'username_key'))
0 ignored issues
show
Documentation introduced by
array($this, 'username_key') is of type array<integer,this<Kohan...ername>","1":"string"}>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
17
18
			->name_key('username')
19
20
			->fields([
21
				'username' => Jam::field('string'),
22
			])
23
24
			->validator('username', array(
25
				'length' => array('minimum' => 3, 'maximum' => 32),
26
				'present' => TRUE,
27
				'format' => array('regex' => '/^[a-zA-Z0-9\_\-]+$/')
28
			));
29
	}
30
31 21
	public function username_key($value)
32
	{
33 21
		return Valid::email($value) ? 'email' : ((is_numeric($value) OR $value === NULL) ? 'id' : 'username');
34
	}
35
36
}
37