Completed
Push — master ( a4e09c...825da9 )
by Michael
01:51
created

PageHandler::updateposts()   D

Complexity

Conditions 10
Paths 8

Size

Total Lines 38
Code Lines 23

Duplication

Lines 18
Ratio 47.37 %

Importance

Changes 0
Metric Value
cc 10
eloc 23
nc 8
nop 3
dl 18
loc 38
rs 4.8196
c 0
b 0
f 0

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php namespace Xoopsmodules\instruction;
2
3
//if (!defined("XOOPS_ROOT_PATH")) {
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...
4
//	die("XOOPS root path not defined");
5
//}
6
7
include_once $GLOBALS['xoops']->path('include/common.php');
8
9
/**
10
 * Class PageHandler
11
 * @package Xoopsmodules\instruction
12
 */
13
class PageHandler extends \XoopsPersistableObjectHandler
14
{
15
    /**
16
     * @param null|mixed $db
17
     */
18
    public function __construct(\XoopsDatabase $db = null)
19
    {
20
        parent::__construct($db, 'instruction_page', Page::class, 'pageid', 'title');
21
    }
22
23
    /**
24
     * Generate function for update user post
25
     *
26
     * @ Update user post count after send approve content
27
     * @ Update user post count after change status content
28
     * @ Update user post count after delete content
29
     * @param $uid
30
     * @param $status
31
     * @param $action
32
     */
33
    public function updateposts($uid, $status, $action)
34
    {
35
        //
36
        switch ($action) {
37
            // Добавление страницы
38 View Code Duplication
            case 'add':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
39
                if ($uid && $status) {
40
                    $user          = new \XoopsUser($uid);
41
                    $memberHandler = xoops_getHandler('member');
42
                    // Добавялем +1 к комментам
43
                    $memberHandler->updateUserByField($user, 'posts', $user->getVar('posts') + 1);
44
                }
45
                break;
46
            // Удаление страницы
47 View Code Duplication
            case 'delete':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
                if ($uid && $status) {
49
                    $user          = new \XoopsUser($uid);
50
                    $memberHandler = xoops_getHandler('member');
51
                    // Декримент комментов
52
                    //$user->setVar( 'posts', $user->getVar( 'posts' ) - 1 );
0 ignored issues
show
Unused Code Comprehensibility introduced by
57% 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...
53
                    // Сохраняем
54
                    $memberHandler->updateUserByField($user, 'posts', $user->getVar('posts') - 1);
55
                }
56
                break;
57
58
            case 'status':
59
                if ($uid) {
60
                    $user          = new \XoopsUser($uid);
61
                    $memberHandler = xoops_getHandler('member');
62
                    if ($status) {
63
                        $memberHandler->updateUserByField($user, 'posts', $user->getVar('posts') - 1);
64
                    } else {
65
                        $memberHandler->updateUserByField($user, 'posts', $user->getVar('posts') + 1);
66
                    }
67
                }
68
                break;
69
        }
70
    }
71
}
72