c-harris /
phpquery
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | interface ICallbackNamed { |
||
|
0 ignored issues
–
show
|
|||
| 3 | function hasName(); |
||
| 4 | function getName(); |
||
| 5 | } |
||
| 6 | /** |
||
| 7 | * Callback class introduces currying-like pattern. |
||
| 8 | * |
||
| 9 | * Example: |
||
| 10 | * function foo($param1, $param2, $param3) { |
||
| 11 | * var_dump($param1, $param2, $param3); |
||
| 12 | * } |
||
| 13 | * $fooCurried = new Callback('foo', |
||
| 14 | * 'param1 is now statically set', |
||
| 15 | * new CallbackParam, new CallbackParam |
||
| 16 | * ); |
||
| 17 | * PhpQuery::callbackRun($fooCurried, |
||
| 18 | * array('param2 value', 'param3 value' |
||
| 19 | * ); |
||
| 20 | * |
||
| 21 | * Callback class is supported in all PhpQuery methods which accepts callbacks. |
||
| 22 | * |
||
| 23 | * @link http://code.google.com/p/phpquery/wiki/Callbacks#Param_Structures |
||
| 24 | * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com> |
||
| 25 | * |
||
| 26 | * @TODO??? return fake forwarding function created via create_function |
||
| 27 | * @TODO honor paramStructure |
||
| 28 | */ |
||
| 29 | class Callback |
||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
|||
| 30 | implements ICallbackNamed { |
||
|
0 ignored issues
–
show
|
|||
| 31 | public $callback = null; |
||
| 32 | public $params = null; |
||
| 33 | protected $name; |
||
| 34 | View Code Duplication | public function __construct($callback, $param1 = null, $param2 = null, |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 35 | $param3 = null) { |
||
|
0 ignored issues
–
show
|
|||
| 36 | $params = func_get_args(); |
||
| 37 | $params = array_slice($params, 1); |
||
| 38 | if ($callback instanceof Callback) { |
||
|
0 ignored issues
–
show
This
if statement is empty and can be removed.
This check looks for the bodies of These if (rand(1, 6) > 3) {
//print "Check failed";
} else {
print "Check succeeded";
}
could be turned into if (rand(1, 6) <= 3) {
print "Check succeeded";
}
This is much more concise to read. Loading history...
|
|||
| 39 | // TODO implement recurention |
||
| 40 | } else { |
||
| 41 | $this->callback = $callback; |
||
| 42 | $this->params = $params; |
||
| 43 | } |
||
| 44 | } |
||
| 45 | public function getName() { |
||
| 46 | return 'Callback: '.$this->name; |
||
| 47 | } |
||
| 48 | public function hasName() { |
||
| 49 | return isset($this->name) && $this->name; |
||
| 50 | } |
||
| 51 | public function setName($name) { |
||
| 52 | $this->name = $name; |
||
| 53 | return $this; |
||
| 54 | } |
||
| 55 | // TODO test me |
||
|
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
42% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. Loading history...
|
|||
| 56 | // public function addParams() { |
||
| 57 | // $params = func_get_args(); |
||
| 58 | // return new Callback($this->callback, $this->params+$params); |
||
| 59 | // } |
||
| 60 | } |
||
| 61 | /** |
||
| 62 | * Shorthand for new Callback(create_function(...), ...); |
||
| 63 | * |
||
| 64 | * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com> |
||
| 65 | */ |
||
| 66 | class CallbackBody extends Callback { |
||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
|||
| 67 | View Code Duplication | public function __construct($paramList, $code, $param1 = null, $param2 = null, |
|
|
0 ignored issues
–
show
This method seems to be duplicated in your project.
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation. You can also find more detailed suggestions in the “Code” section of your repository. Loading history...
|
|||
| 68 | $param3 = null) { |
||
|
0 ignored issues
–
show
|
|||
| 69 | $params = func_get_args(); |
||
| 70 | $params = array_slice($params, 2); |
||
| 71 | $this->callback = create_function($paramList, $code); |
||
|
0 ignored issues
–
show
The use of
create_function is highly discouraged, better use a closure.
// Instead of
$function = create_function('$a, $b', 'return $a + $b');
// Better use
$function = function($a, $b) { return $a + $b; }
Loading history...
|
|||
| 72 | $this->params = $params; |
||
| 73 | } |
||
| 74 | } |
||
| 75 | /** |
||
| 76 | * Callback type which on execution returns reference passed during creation. |
||
| 77 | * |
||
| 78 | * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com> |
||
| 79 | */ |
||
| 80 | class CallbackReturnReference extends Callback |
||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
|||
| 81 | implements ICallbackNamed { |
||
|
0 ignored issues
–
show
|
|||
| 82 | protected $reference; |
||
| 83 | public function __construct(&$reference, $name = null){ |
||
| 84 | $this->reference =& $reference; |
||
| 85 | $this->callback = array($this, 'callback'); |
||
| 86 | } |
||
| 87 | public function callback() { |
||
| 88 | return $this->reference; |
||
| 89 | } |
||
| 90 | public function getName() { |
||
| 91 | return 'Callback: '.$this->name; |
||
| 92 | } |
||
| 93 | public function hasName() { |
||
| 94 | return isset($this->name) && $this->name; |
||
| 95 | } |
||
| 96 | } |
||
| 97 | /** |
||
| 98 | * Callback type which on execution returns value passed during creation. |
||
| 99 | * |
||
| 100 | * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com> |
||
| 101 | */ |
||
| 102 | class CallbackReturnValue extends Callback |
||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
|||
| 103 | implements ICallbackNamed { |
||
|
0 ignored issues
–
show
|
|||
| 104 | protected $value; |
||
| 105 | protected $name; |
||
| 106 | public function __construct($value, $name = null){ |
||
| 107 | $this->value =& $value; |
||
| 108 | $this->name = $name; |
||
| 109 | $this->callback = array($this, 'callback'); |
||
| 110 | } |
||
| 111 | public function callback() { |
||
| 112 | return $this->value; |
||
| 113 | } |
||
| 114 | public function __toString() { |
||
| 115 | return $this->getName(); |
||
| 116 | } |
||
| 117 | public function getName() { |
||
| 118 | return 'Callback: '.$this->name; |
||
| 119 | } |
||
| 120 | public function hasName() { |
||
| 121 | return isset($this->name) && $this->name; |
||
| 122 | } |
||
| 123 | } |
||
| 124 | /** |
||
| 125 | * CallbackParameterToReference can be used when we don't really want a callback, |
||
| 126 | * only parameter passed to it. CallbackParameterToReference takes first |
||
| 127 | * parameter's value and passes it to reference. |
||
| 128 | * |
||
| 129 | * @author Tobiasz Cudnik <tobiasz.cudnik/gmail.com> |
||
| 130 | */ |
||
| 131 | class CallbackParameterToReference extends Callback { |
||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
|||
| 132 | /** |
||
| 133 | * @param $reference |
||
| 134 | * @TODO implement $paramIndex; |
||
| 135 | * param index choose which callback param will be passed to reference |
||
| 136 | */ |
||
| 137 | public function __construct(&$reference){ |
||
| 138 | $this->callback =& $reference; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | //class CallbackReference extends Callback { |
||
| 142 | // /** |
||
| 143 | // * |
||
| 144 | // * @param $reference |
||
| 145 | // * @param $paramIndex |
||
| 146 | // * @todo implement $paramIndex; param index choose which callback param will be passed to reference |
||
| 147 | // */ |
||
| 148 | // public function __construct(&$reference, $name = null){ |
||
| 149 | // $this->callback =& $reference; |
||
| 150 | // } |
||
| 151 | //} |
||
| 152 | class CallbackParam {} |
||
|
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. Loading history...
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.