Completed
Push — master ( 88111b...b3fce7 )
by Michael
05:58
created

AdsenseHandler   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 116
rs 10
c 0
b 0
f 0
wmc 7
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 66 1
A getFormats() 0 4 1
A beforeSave() 0 8 2
A getAdsensesByTag() 0 13 3
1
<?php namespace XoopsModules\Smartobject;
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    XOOPS Project https://xoops.org/
15
 * @license      GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
16
 * @package
17
 * @since
18
 * @author     XOOPS Development Team
19
 */
20
21
use XoopsModules\Smartobject;
22
23
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% 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...
24
25
//require_once XOOPS_ROOT_PATH . '/modules/smartobject/class/smartobject.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
38% 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...
26
27
28
/**
29
 * Class SmartobjectAdsenseHandler
30
 */
31
class AdsenseHandler extends Smartobject\PersistableObjectHandler
32
{
33
    public $adFormats;
34
    public $adFormatsList;
35
    public $objects = false;
36
//    public $classname = Adsense::class;
0 ignored issues
show
Unused Code Comprehensibility introduced by
37% 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...
37
38
    /**
39
     * SmartobjectAdsenseHandler constructor.
40
     * @param \XoopsDatabase $db
41
     */
42
    public function __construct(\XoopsDatabase $db)
43
    {
44
        parent::__construct($db, Adsense::class, 'adsenseid', 'description', '', 'smartobject');
45
        $this->adFormats     = [];
46
        $this->adFormatsList = [];
47
48
        $this->adFormats['728x90_as']['caption'] = '728 X 90 Leaderboard';
49
        $this->adFormats['728x90_as']['width']   = 728;
50
        $this->adFormats['728x90_as']['height']  = 90;
51
        $this->adFormatsList['728x90_as']        = $this->adFormats['728x90_as']['caption'];
52
53
        $this->adFormats['468x60_as']['caption'] = '468 X 60 Banner';
54
        $this->adFormats['468x60_as']['width']   = 468;
55
        $this->adFormats['468x60_as']['height']  = 60;
56
        $this->adFormatsList['468x60_as']        = $this->adFormats['468x60_as']['caption'];
57
58
        $this->adFormats['234x60_as']['caption'] = '234 X 60 Half Banner';
59
        $this->adFormats['234x60_as']['width']   = 234;
60
        $this->adFormats['234x60_as']['height']  = 60;
61
        $this->adFormatsList['234x60_as']        = $this->adFormats['234x60_as']['caption'];
62
63
        $this->adFormats['120x600_as']['caption'] = '120 X 600 Skyscraper';
64
        $this->adFormats['120x600_as']['width']   = 120;
65
        $this->adFormats['120x600_as']['height']  = 600;
66
        $this->adFormatsList['120x600_as']        = $this->adFormats['120x600_as']['caption'];
67
68
        $this->adFormats['160x600_as']['caption'] = '160 X 600 Wide Skyscraper';
69
        $this->adFormats['160x600_as']['width']   = 160;
70
        $this->adFormats['160x600_as']['height']  = 600;
71
        $this->adFormatsList['160x600_as']        = $this->adFormats['160x600_as']['caption'];
72
73
        $this->adFormats['120x240_as']['caption'] = '120 X 240 Vertical Banner';
74
        $this->adFormats['120x240_as']['width']   = 120;
75
        $this->adFormats['120x240_as']['height']  = 240;
76
        $this->adFormatsList['120x240_as']        = $this->adFormats['120x240_as']['caption'];
77
78
        $this->adFormats['336x280_as']['caption'] = '336 X 280 Large Rectangle';
79
        $this->adFormats['336x280_as']['width']   = 136;
80
        $this->adFormats['336x280_as']['height']  = 280;
81
        $this->adFormatsList['336x280_as']        = $this->adFormats['336x280_as']['caption'];
82
83
        $this->adFormats['300x250_as']['caption'] = '300 X 250 Medium Rectangle';
84
        $this->adFormats['300x250_as']['width']   = 300;
85
        $this->adFormats['300x250_as']['height']  = 250;
86
        $this->adFormatsList['300x250_as']        = $this->adFormats['300x250_as']['caption'];
87
88
        $this->adFormats['250x250_as']['caption'] = '250 X 250 Square';
89
        $this->adFormats['250x250_as']['width']   = 250;
90
        $this->adFormats['250x250_as']['height']  = 250;
91
        $this->adFormatsList['250x250_as']        = $this->adFormats['250x250_as']['caption'];
92
93
        $this->adFormats['200x200_as']['caption'] = '200 X 200 Small Square';
94
        $this->adFormats['200x200_as']['width']   = 200;
95
        $this->adFormats['200x200_as']['height']  = 200;
96
        $this->adFormatsList['200x200_as']        = $this->adFormats['200x200_as']['caption'];
97
98
        $this->adFormats['180x150_as']['caption'] = '180 X 150 Small Rectangle';
99
        $this->adFormats['180x150_as']['width']   = 180;
100
        $this->adFormats['180x150_as']['height']  = 150;
101
        $this->adFormatsList['180x150_as']        = $this->adFormats['180x150_as']['caption'];
102
103
        $this->adFormats['125x125_as']['caption'] = '125 X 125 Button';
104
        $this->adFormats['125x125_as']['width']   = 125;
105
        $this->adFormats['125x125_as']['height']  = 125;
106
        $this->adFormatsList['125x125_as']        = $this->adFormats['125x125_as']['caption'];
107
    }
108
109
    /**
110
     * @return array
111
     */
112
    public function getFormats()
113
    {
114
        return $this->adFormatsList;
115
    }
116
117
    /**
118
     * @param $obj
119
     * @return bool
120
     */
121
    public function beforeSave($obj)
122
    {
123
        if ('' === $obj->getVar('tag')) {
124
            $obj->setVar('tag', $title = $obj->generateTag());
125
        }
126
127
        return true;
128
    }
129
130
    /**
131
     * @return array|bool
132
     */
133
    public function getAdsensesByTag()
134
    {
135
        if (!$this->objects) {
136
            $adsensesObj =& $this->getObjects(null, true);
137
            $ret         = [];
138
            foreach ($adsensesObj as $adsenseObj) {
139
                $ret[$adsenseObj->getVar('tag')] = $adsenseObj;
140
            }
141
            $this->objects = $ret;
0 ignored issues
show
Documentation Bug introduced by
It seems like $ret of type array is incompatible with the declared type boolean of property $objects.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
142
        }
143
144
        return $this->objects;
145
    }
146
}
147