1 | <?php defined('SYSPATH') OR die('No direct script access.'); |
||
15 | abstract class Kohana_Jam_Field_Serialized extends Jam_Field { |
||
16 | |||
17 | public static $allowed = array('native', 'json', 'csv', 'query'); |
||
18 | |||
19 | public $method = 'native'; |
||
20 | |||
21 | public function initialize(Jam_Meta $meta, $name) |
||
22 | { |
||
23 | parent::initialize($meta, $name); |
||
24 | |||
25 | if ( ! in_array($this->method, Jam_Field_Serialized::$allowed)) |
||
26 | throw new Kohana_Exception("Unnown serialization method ':method', can use only :allowed", array(':method' => $this->method, ':allowed' => Jam_Field_Serialized::$allowed)); |
||
27 | } |
||
28 | |||
29 | /** |
||
30 | * Unserializes data as soon as it comes in. |
||
31 | * |
||
32 | * Incoming data that isn't actually serialized will not be harmed. |
||
33 | * |
||
34 | * @param mixed $value |
||
35 | * @return mixed |
||
36 | */ |
||
37 | 3 | public function set(Jam_Validated $model, $value, $is_changed) |
|
38 | { |
||
39 | 3 | list($value, $return) = $this->_default($model, $value); |
|
40 | |||
41 | 3 | if ( ! $return) |
|
42 | 3 | { |
|
43 | 3 | if (is_string($value) AND ($new_value = $this->unserialize($value)) !== FALSE) |
|
44 | 3 | { |
|
45 | 2 | $value = $new_value; |
|
46 | 2 | } |
|
47 | 3 | } |
|
48 | |||
49 | 3 | return $value; |
|
50 | } |
||
51 | |||
52 | /** |
||
53 | * Saves the value as a serialized string. |
||
54 | * |
||
55 | * @param Jam_Model $model |
||
56 | * @param mixed $value |
||
57 | * @param boolean $loaded |
||
|
|||
58 | * @return null|string |
||
59 | */ |
||
60 | public function convert(Jam_Validated $model, $value, $is_loaded) |
||
61 | { |
||
62 | if ($this->allow_null AND $value === NULL) |
||
63 | { |
||
64 | return NULL; |
||
65 | } |
||
66 | |||
67 | return $this->serialize($value); |
||
68 | } |
||
69 | |||
70 | public function serialize($value) |
||
87 | |||
88 | 2 | public function unserialize($value) |
|
106 | |||
107 | } // Kohana_Jam_Field_Serialized |
||
108 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.