BackgroundController::actionContestStart()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 9
nc 4
nop 1
1
<?php
2
class BackgroundController extends CronController
3
{
4
    public function actionFinishChallenges()
5
    {
6
        $mc = new MaintenanceChallenge;
7
        $mc->fetchFinishable();
8
        $mc->process();
9
10
        echo 'ok';
11
    }
12
13
    public function actionReset()
14
    {
15
        $mp = new MaintenancePlayer;
16
17
        $user = Yii::app()->request->getParam('user', 'x');
18
        echo $user . '<br/>';
19
20
        if ($user) {
21
            $mp->setUid($user);
22
        }
23
        $mp->reset();
24
25
        $this->render('//site/dummy', ['log'=>$mp->log]);
26
    }
27
28
    public function actionContestStart($addPoints = 0)
29
    {
30
        $contest = new Contest;
31
        if ($contest->activeId) {
0 ignored issues
show
Bug introduced by
The property activeId cannot be accessed from this context as it is declared private in class Contest.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
32
            return true;
33
        }
34
        echo 'started, ';
35
36
        $contest->create();
37
38
        if ($addPoints) {
39
            for ($i=0; $i<1000; $i++) {
40
                $contest->addPoints(rand(1981, 2100), Contest::ACT_MISSION, 1, 1, 1);
41
            }
42
        }
43
    }
44
45
    public function actionContestStop()
46
    {
47
        $contest = new Contest;
48
        if (time() > $contest->activeId + CONTEST::LIFETIME) {
0 ignored issues
show
Bug introduced by
The property activeId cannot be accessed from this context as it is declared private in class Contest.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
49
            echo 'stopped:'. $contest->activeId;
0 ignored issues
show
Bug introduced by
The property activeId cannot be accessed from this context as it is declared private in class Contest.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
50
            $contest->complete();
51
        }
52
    }
53
54
    public function actionContestStartStop($addPoints = 0)
55
    {
56
        $this->actionContestStart($addPoints);
57
        $this->actionContestStop();
58
    }
59
60
    public function actionNewLevelRevards()
61
    {
62
        $res = Yii::app()->db->createCommand()
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
63
            ->select('uid, routine')
64
            ->from('visited')
65
            ->where('routine >= 9')
66
            ->order('uid')
67
            ->queryAll();
68
        $users = [];
69
        foreach ($res as $d) {
70
            //pay for gold routine
71
            @$users[$d['uid']]['gold'] += 30;
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
72
            @$users[$d['uid']]['r_gold']++;
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
73
74
            //pay for diamand
75
            if ($d['routine'] >= 81) {
76
                $users[$d['uid']]['gold'] += 70;
77
                @$users[$d['uid']]['r_diamant']++;
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
78
            }
79
        }
80
81
        $log = print_r($users, true);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
82
        $wall = new Wall();
83
        foreach ($users as $uid => $award) {
84
            Yii::app()->db->createCommand("UPDATE main SET gold=gold+{$award['gold']} WHERE uid={$uid}")->execute();
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $award instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $uid instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
85
86
            $wall->content_type = Wall::TYPE_NEW_AWARD;
0 ignored issues
show
Bug introduced by
The property content_type cannot be accessed from this context as it is declared private in class Wall.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
87
            $wall->uid = $uid;
0 ignored issues
show
Bug introduced by
The property uid cannot be accessed from this context as it is declared private in class Wall.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
88
            $wall->add([
89
                'award'=>$award['gold'],
90
                'r_gold'=>$award['r_gold'],
91
                'r_diamant'=>(int)@$award['r_diamant']
92
                ]);
93
        }
94
        $this->render('//site/dummy', ['log'=>$log]);
95
    }
96
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
97