Utility::getMetaKeywords()   A
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 28
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 19
nc 6
nop 2
dl 0
loc 28
rs 9.3222
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Xooghost;
4
5
/**
6
 * Created by PhpStorm.
7
 * User: mamba
8
 * Date: 2015-10-11
9
 * Time: 00:08
10
 */
11
class Utility
12
{
13
    /**
14
     * @param $string
15
     *
16
     * @return mixed|string
17
     */
18
    public function getMetaDescription($string)
19
    {
20
        $xoops = \Xoops::getInstance();
21
        $myts = \MyTextSanitizer::getInstance();
22
23
        if (is_array($string)) {
24
            $string = implode(', ', $string);
25
        }
26
        $string = $xoops->module->name() . ' : ' . $string;
0 ignored issues
show
Bug introduced by
The method name() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

26
        $string = $xoops->module->/** @scrutinizer ignore-call */ name() . ' : ' . $string;

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
27
        $string .= '. ' . $xoops->getConfig('meta_description', 3);
0 ignored issues
show
Unused Code introduced by
The call to Xoops::getConfig() has too many arguments starting with 3. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

27
        $string .= '. ' . $xoops->/** @scrutinizer ignore-call */ getConfig('meta_description', 3);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
28
29
        $string = $myts->undoHtmlSpecialChars($string);
30
        $string = str_replace('[breakpage]', '', $string);
31
        // remove html tags
32
        $string = strip_tags($string);
33
34
        return $string;
35
    }
36
37
    /**
38
     * @param     $string
39
     * @param int $limit
40
     *
41
     * @return string
42
     */
43
    public function getMetaKeywords($string, $limit = 5)
44
    {
45
        $xoops = \Xoops::getInstance();
46
        $myts = \MyTextSanitizer::getInstance();
47
        $keywords = [];
48
        if (is_array($string)) {
49
            $string = implode(', ', $string);
50
        }
51
        $string = mb_strtolower($string) . ', ' . mb_strtolower($xoops->getConfig('meta_keywords', 3));
0 ignored issues
show
Unused Code introduced by
The call to Xoops::getConfig() has too many arguments starting with 3. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

51
        $string = mb_strtolower($string) . ', ' . mb_strtolower($xoops->/** @scrutinizer ignore-call */ getConfig('meta_keywords', 3));

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
52
        $string = $myts->undoHtmlSpecialChars($string);
53
        $string = str_replace('[breakpage]', '', $string);
54
        $string = strip_tags($string);
55
        $string = html_entity_decode($string, ENT_QUOTES);
56
57
        $search_pattern = ["\t", "\r\n", "\r", "\n", ',', '.', "'", ';', ':', ')', '(', '"', '?', '!', '{', '}', '[', ']', '<', '>', '/', '+', '_', '\\', '*', 'pagebreak', 'page'];
58
        $replace_pattern = [' ', ' ', ' ', ' ', ' ', ' ', ' ', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''];
59
        $string = str_replace($search_pattern, $replace_pattern, $string);
60
61
        $tmpkeywords = explode(' ', $string);
62
63
        $tmpkeywords = array_unique($tmpkeywords);
64
        foreach ($tmpkeywords as $keyword) {
65
            if (mb_strlen(trim($keyword)) >= $limit && !is_numeric($keyword)) {
66
                $keywords[] = htmlentities(trim($keyword));
67
            }
68
        }
69
70
        return implode(', ', $keywords);
71
    }
72
}
73