Completed
Push — cli ( eb8d78 )
by Andreas
03:57
created

lib/plugins/popularity/action.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
/**
3
 * Popularity Feedback Plugin
4
 *
5
 * @license    GPL 2 (http://www.gnu.org/licenses/gpl.html)
6
 */
7
8
require_once(DOKU_PLUGIN.'action.php');
9
require_once(DOKU_PLUGIN.'popularity/admin.php');
10
11
class action_plugin_popularity extends Dokuwiki_Action_Plugin {
12
13
    /**
14
     * @var helper_plugin_popularity
15
     */
16
    var $helper;
17
18
    function __construct(){
19
        $this->helper = $this->loadHelper('popularity', false);
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->loadHelper('popularity', false) can also be of type object<DokuWiki_PluginInterface>. However, the property $helper is declared as type object<helper_plugin_popularity>. 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 $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

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...
20
    }
21
22
    /**
23
     * Register its handlers with the dokuwiki's event controller
24
     */
25
    function register(Doku_Event_Handler $controller) {
26
        $controller->register_hook('INDEXER_TASKS_RUN', 'AFTER',  $this, '_autosubmit', array());
27
    }
28
29
    function _autosubmit(Doku_Event &$event, $param){
30
        //Do we have to send the data now
31
        if ( !$this->helper->isAutosubmitEnabled() || $this->_isTooEarlyToSubmit() ){
32
            return;
33
        }
34
35
        //Actually send it
36
        $status = $this->helper->sendData( $this->helper->gatherAsString() );
37
38
        if ( $status !== '' ){
39
            //If an error occured, log it
40
            io_saveFile( $this->helper->autosubmitErrorFile, $status );
41
        } else {
42
            //If the data has been sent successfully, previous log of errors are useless
43
            @unlink($this->helper->autosubmitErrorFile);
44
            //Update the last time we sent data
45
            touch ( $this->helper->autosubmitFile );
46
        }
47
48
        $event->stopPropagation();
49
        $event->preventDefault();
50
    }
51
52
    /**
53
     * Check if it's time to send autosubmit data
54
     * (we should have check if autosubmit is enabled first)
55
     */
56
    function _isTooEarlyToSubmit(){
57
        $lastSubmit = $this->helper->lastSentTime();
58
        return $lastSubmit + 24*60*60*30 > time();
59
    }
60
}
61