WebDevStudios /
CMB2
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Base class for hooking CMB2 into WordPress. |
||
| 4 | * |
||
| 5 | * @since 2.2.0 |
||
| 6 | * |
||
| 7 | * @category WordPress_Plugin |
||
| 8 | * @package CMB2 |
||
| 9 | * @author WebDevStudios |
||
| 10 | * @license GPL-2.0+ |
||
| 11 | * @link http://webdevstudios.com |
||
| 12 | */ |
||
| 13 | abstract class CMB2_Hookup_Base { |
||
|
0 ignored issues
–
show
|
|||
| 14 | |||
| 15 | /** |
||
| 16 | * Array of all hooks done (to be run once) |
||
| 17 | * @var array |
||
| 18 | * @since 2.0.0 |
||
| 19 | */ |
||
| 20 | protected static $hooks_completed = array(); |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var CMB2 object |
||
| 24 | * @since 2.0.2 |
||
| 25 | */ |
||
| 26 | protected $cmb; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * The object type we are performing the hookup for |
||
| 30 | * @var string |
||
| 31 | * @since 2.0.9 |
||
| 32 | */ |
||
| 33 | protected $object_type = 'post'; |
||
| 34 | |||
| 35 | public function __construct( CMB2 $cmb ) { |
||
| 36 | $this->cmb = $cmb; |
||
| 37 | $this->object_type = $this->cmb->mb_object_type(); |
||
|
0 ignored issues
–
show
It seems like
$this->cmb->mb_object_type() can also be of type false. However, the property $object_type is declared as type string. Maybe add an additional type check?
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly. For example, imagine you have a variable Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
| 38 | } |
||
| 39 | |||
| 40 | abstract public function universal_hooks(); |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Ensures WordPress hook only gets fired once |
||
| 44 | * @since 2.0.0 |
||
| 45 | * @param string $action The name of the filter to hook the $hook callback to. |
||
| 46 | * @param callback $hook The callback to be run when the filter is applied. |
||
| 47 | * @param integer $priority Order the functions are executed |
||
| 48 | * @param int $accepted_args The number of arguments the function accepts. |
||
| 49 | */ |
||
| 50 | public function once( $action, $hook, $priority = 10, $accepted_args = 1 ) { |
||
| 51 | $key = md5( serialize( func_get_args() ) ); |
||
| 52 | |||
| 53 | if ( in_array( $key, self::$hooks_completed ) ) { |
||
| 54 | return; |
||
| 55 | } |
||
| 56 | |||
| 57 | self::$hooks_completed[] = $key; |
||
| 58 | add_filter( $action, $hook, $priority, $accepted_args ); |
||
| 59 | } |
||
| 60 | |||
| 61 | } |
||
| 62 |
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.