1 | <?php |
||
11 | class Kohana_Jam_Field_Price extends Jam_Field_String { |
||
12 | |||
13 | public $default = 0; |
||
14 | |||
15 | public $allow_null = TRUE; |
||
16 | |||
17 | public $convert_empty = TRUE; |
||
18 | |||
19 | public $default_currency = 'GBP'; |
||
20 | |||
21 | public $default_display_currency = 'GBP'; |
||
22 | |||
23 | public $default_ceil_on_convert = FALSE; |
||
24 | |||
25 | public static $autoload_from_model = array('currency', 'display_currency', 'monetary', 'ceil_on_convert'); |
||
26 | |||
27 | /** |
||
28 | * Casts to a string, preserving NULLs along the way. |
||
29 | * |
||
30 | * @param mixed $value |
||
31 | * @return string |
||
32 | */ |
||
33 | 2 | public function set(Jam_Validated $model, $value, $is_changed) |
|
39 | |||
40 | /** |
||
41 | * Preserve nulls and 0 / 0.0 values |
||
42 | * @param Jam_Validated $model |
||
43 | * @param mixed $value |
||
44 | * @return array |
||
45 | */ |
||
46 | 2 | protected function _default(Jam_Validated $model, $value) |
|
47 | { |
||
48 | 2 | $return = FALSE; |
|
49 | |||
50 | 2 | $value = $this->run_filters($model, $value); |
|
51 | 2 | if (is_string($value)) { |
|
52 | $value = (float) $value; |
||
53 | } |
||
54 | |||
55 | // Convert empty values to NULL, if needed |
||
56 | 2 | if ($this->convert_empty AND empty($value) AND $value !== 0 AND $value !== 0.0) |
|
57 | 2 | { |
|
58 | 1 | $value = $this->empty_value; |
|
59 | 1 | $return = TRUE; |
|
60 | 1 | } |
|
61 | |||
62 | // Allow NULL values to pass through untouched by the field |
||
63 | 2 | if ($this->allow_null AND $value === NULL) |
|
64 | 2 | { |
|
65 | 1 | $value = NULL; |
|
66 | 1 | $return = TRUE; |
|
67 | 1 | } |
|
68 | |||
69 | 2 | return array($value, $return); |
|
70 | } |
||
71 | |||
72 | 2 | public function monetary() |
|
76 | |||
77 | /** |
||
78 | * convert to Jam_Price if not NULL |
||
79 | * @param Jam_Validated $model |
||
80 | * @param mixed $value |
||
81 | * @param boolean $is_loaded |
||
82 | * @return Jam_Price |
||
83 | */ |
||
84 | 2 | public function get(Jam_Validated $model, $value, $is_loaded) |
|
101 | } |
||
102 |
This checks looks for assignemnts to variables using the
list(...)
function, where not all assigned variables are subsequently used.Consider the following code example.
Only the variables
$a
and$c
are used. There was no need to assign$b
.Instead, the list call could have been.