Skip to content

Commit

Permalink
more phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Nov 10, 2023
1 parent eac70da commit 718303f
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion ajax/dropdownQuantity.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

Session::checkLoginUser();

/** @var DBmysql */
/** @var DBmysql $DB */
global $DB;

if (isset($_POST["entity"])) {
Expand Down
2 changes: 1 addition & 1 deletion hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ function plugin_credit_getDropdown()

function plugin_credit_get_datas(NotificationTargetTicket $target)
{

/** @var DBmysql $DB */
global $DB;

$target->data['##lang.credit.voucher##'] = PluginCreditEntity::getTypeName();
Expand Down
11 changes: 9 additions & 2 deletions inc/entity.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function getTypeName($nb = 0)
return _n('Credit voucher', 'Credit vouchers', $nb, 'credit');
}

public function getTabNameForItem(CommonGLPI $item, $withtemplate = false)
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
$nb = self::countForItem($item);
switch ($item->getType()) {
Expand All @@ -57,7 +57,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = false)
return '';
}

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = false)
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
switch ($item->getType()) {
case 'Entity':
Expand Down Expand Up @@ -123,6 +123,7 @@ public function post_purgeItem()
*/
public static function getAllForEntity($ID, $sqlfilter = []): array
{
/** @var DBmysql $DB */
global $DB;

$request = [
Expand Down Expand Up @@ -443,6 +444,10 @@ public static function cronInfo($name)

public static function cronCreditExpired($task)
{
/**
* @var array $CFG_GLPI
* @var DBmysql $DB
*/
global $CFG_GLPI, $DB;

if (!$CFG_GLPI['use_notifications']) {
Expand Down Expand Up @@ -521,6 +526,7 @@ public static function cronCreditExpired($task)
*/
public static function install(Migration $migration)
{
/** @var DBmysql $DB */
global $DB;

$default_charset = DBConnection::getDefaultCharset();
Expand Down Expand Up @@ -582,6 +588,7 @@ public static function uninstall(Migration $migration)

public static function getActiveFilter()
{
/** @var DBmysql $DB */
global $DB;
return [
'glpi_plugin_credit_entities.is_active' => 1,
Expand Down
1 change: 1 addition & 0 deletions inc/entityconfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ public static function getDefaultForEntityAndType($entity_id, $itemtype)

public static function install(Migration $migration)
{
/** @var DBmysql $DB */
global $DB;

$default_charset = DBConnection::getDefaultCharset();
Expand Down
3 changes: 3 additions & 0 deletions inc/notificationtargetentity.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public function getEvents()

public function addDataForTemplate($event, $options = [])
{
/** @var DBmysql $DB */
global $DB;

$this->data['##credit.name##'] = $this->obj->getField('name');
Expand Down Expand Up @@ -116,6 +117,7 @@ public function getTags()

public static function install(Migration $migration)
{
/** @var DBmysql $DB */
global $DB;

$template = new NotificationTemplate();
Expand Down Expand Up @@ -209,6 +211,7 @@ public static function install(Migration $migration)

public static function uninstall()
{
/** @var DBmysql $DB */
global $DB;

$notification = new Notification();
Expand Down
4 changes: 2 additions & 2 deletions inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@

class PluginCreditProfile extends Profile
{
public function getTabNameForItem(CommonGLPI $item, $withtemplate = false)
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
return self::createTabEntry(PluginCreditTicket::getTypeName(Session::getPluralNumber()));
}

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = false)
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
$profile = new self();
/** @phpstan-ignore-next-line */
Expand Down
13 changes: 8 additions & 5 deletions inc/ticket.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static function getTypeName($nb = 0)
return _n('Credit voucher', 'Credit vouchers', $nb, 'credit');
}

public function getTabNameForItem(CommonGLPI $item, $withtemplate = false)
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
$nb = self::countForItem($item);
switch ($item->getType()) {
Expand All @@ -58,7 +58,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = false)
return '';
}

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = false)
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
switch ($item->getType()) {
case 'Ticket':
Expand All @@ -84,6 +84,7 @@ public static function countForItem(CommonDBTM $item)
*/
public static function getAllForTicket($ID): array
{
/** @var DBmysql $DB */
global $DB;

$request = [
Expand Down Expand Up @@ -112,6 +113,7 @@ public static function getAllForTicket($ID): array
**/
public static function getAllForCreditEntity($ID): array
{
/** @var DBmysql $DB */
global $DB;

$request = [
Expand All @@ -138,6 +140,7 @@ public static function getAllForCreditEntity($ID): array
**/
public static function getConsumedForCreditEntity($ID)
{
/** @var DBmysql $DB */
global $DB;

$tot = 0;
Expand Down Expand Up @@ -166,7 +169,8 @@ public static function getConsumedForCreditEntity($ID)
**/
public static function showForTicket(Ticket $ticket)
{
global $DB, $CFG_GLPI;
/** @var DBmysql $DB */
global $DB;

$ID = $ticket->getField('id');
if (!$ticket->can($ID, READ)) {
Expand Down Expand Up @@ -347,8 +351,6 @@ public static function showForTicket(Ticket $ticket)
public static function displayVoucherInTicketProcessingForm($params)
{

global $CFG_GLPI;

$item = $params['item'];

if ($item instanceof Ticket) {
Expand Down Expand Up @@ -706,6 +708,7 @@ public function rawSearchOptions()
*/
public static function install(Migration $migration)
{
/** @var DBmysql $DB */
global $DB;

$default_charset = DBConnection::getDefaultCharset();
Expand Down
1 change: 1 addition & 0 deletions inc/ticketconfig.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ public static function updateConfig(Ticket $ticket)

public static function install(Migration $migration)
{
/** @var DBmysql $DB */
global $DB;

$table = self::getTable();
Expand Down
1 change: 1 addition & 0 deletions inc/type.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public static function getTypeName($nb = 0)
*/
public static function install(Migration $migration)
{
/** @var DBmysql $DB */
global $DB;

$default_charset = DBConnection::getDefaultCharset();
Expand Down
8 changes: 5 additions & 3 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ parameters:
level: 2
bootstrapFiles:
- ../../inc/based_config.php
- setup.php
paths:
- inc
- front
- ajax
- front
- inc
- hook.php
- setup.php
scanDirectories:
- ../../inc
- ../../src
stubFiles:
- ../../stubs/glpi_constants.php
rules:
- GlpiProject\Tools\PHPStan\Rules\GlobalVarTypeRule
3 changes: 2 additions & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
*/
function plugin_init_credit()
{
global $PLUGIN_HOOKS, $CFG_GLPI;
/** @var array $PLUGIN_HOOKS */
global $PLUGIN_HOOKS;

$plugin = new Plugin();

Expand Down

0 comments on commit 718303f

Please sign in to comment.