Simplify   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseUserNick() 0 14 3
A parseUserLink() 0 9 3
1
<?php
2
3
namespace Ffcms\Core\Helper;
4
5
use Ffcms\Core\App;
6
use Ffcms\Core\Helper\Type\Any;
7
use Ffcms\Templex\Url\Url;
0 ignored issues
show
Bug introduced by
The type Ffcms\Templex\Url\Url was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
9
/**
10
 * Class Simplify. Simplification of ofter used logic and methods.
11
 * @package Ffcms\Core\Helper
12
 */
13
class Simplify
14
{
15
    /**
16
     * Get user nickname by user id with predefined value on empty or not exist profile
17
     * @param $userId
18
     * @param string $onEmpty
19
     * @return string
20
     */
21
    public static function parseUserNick($userId = null, $onEmpty = 'guest'): ?string
22
    {
23
        if (!Any::isInt($userId)) {
24
            return \App::$Security->strip_tags($onEmpty);
0 ignored issues
show
Bug introduced by
The property Security does not seem to exist on Illuminate\Support\Facades\App.
Loading history...
25
        }
26
27
        // try to find user active record as object
28
        $identity = App::$User->identity($userId);
29
        if (!$identity) {
30
            return \App::$Security->strip_tags($onEmpty);
31
        }
32
33
        // return user nickname from profile
34
        return $identity->profile->getNickname();
0 ignored issues
show
Bug introduced by
Accessing profile on the interface Ffcms\Core\Interfaces\iUser suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
35
    }
36
37
    /**
38
     * Prepare HTML DOM link (a href) to user with him name or guest name without link
39
     * @param int $userId
40
     * @param string $onEmpty
41
     * @param string $controllerAction
42
     * @return string
43
     */
44
    public static function parseUserLink($userId = null, $onEmpty = 'guest', $controllerAction = 'profile/show')
45
    {
46
        $nick = self::parseUserNick($userId, $onEmpty);
47
        // new name is not found, lets return default
48
        if ($nick === $onEmpty || (int)$userId < 1) {
49
            return $nick;
50
        }
51
52
        return Url::a([$controllerAction, [(int)$userId]], $nick);
53
    }
54
}
55