Passed
Push — master ( ad0973...f9c297 )
by Kacper
02:48
created

Sass::setupRules()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
Code Lines 23

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 36
rs 8.8571
cc 1
eloc 23
nc 1
nop 0
1
<?php
2
/**
3
 * Highlighter
4
 *
5
 * Copyright (C) 2016, Some right reserved.
6
 *
7
 * @author Kacper "Kadet" Donat <[email protected]>
8
 *
9
 * Contact with author:
10
 * Xmpp: [email protected]
11
 * E-mail: [email protected]
12
 *
13
 * From Kadet with love.
14
 */
15
16
namespace Kadet\Highlighter\Language\Css;
17
18
use Kadet\Highlighter\Matcher\RegexMatcher;
19
use Kadet\Highlighter\Parser\Rule;
20
use Kadet\Highlighter\Parser\Token\MetaToken;
21
use Kadet\Highlighter\Parser\Token\Token;
22
use Kadet\Highlighter\Parser\TokenFactory;
23
use Kadet\Highlighter\Parser\Validator\Validator;
24
25
class Sass extends Scss
26
{
27
28
    /**
29
     * Tokenization rules
30
     *
31
     * @return \Kadet\Highlighter\Parser\Rule[]|\Kadet\Highlighter\Parser\Rule[][]
32
     */
33
    public function setupRules()
34
    {
35
        parent::setupRules();
36
37
        $this->rules->remove('meta.selector');
1 ignored issue
show
Unused Code introduced by
The call to the method Kadet\Highlighter\Parser\Rules::remove() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
38
        $this->rules->remove('meta.declaration');
1 ignored issue
show
Unused Code introduced by
The call to the method Kadet\Highlighter\Parser\Rules::remove() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
39
        $this->rules->remove('meta.declaration.media');
1 ignored issue
show
Unused Code introduced by
The call to the method Kadet\Highlighter\Parser\Rules::remove() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
40
        $this->rules->remove('meta.selector.tag');
1 ignored issue
show
Unused Code introduced by
The call to the method Kadet\Highlighter\Parser\Rules::remove() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
41
42
        $this->rules->add('meta.selector', new Rule(new RegexMatcher('/(?=(?:\n+|^)(\h*)([^\h].*)\n+\1\h+)/', [
43
            2 => Token::NAME
44
        ]), [
45
            'context'  => Validator::everywhere(),
46
            'priority' => 3,
47
            'factory'  => new TokenFactory(MetaToken::class)
48
        ]));
49
50
        $this->rules->add('meta.declaration', new Rule(new RegexMatcher('/\n((?:\h+.*?(?>\n|$)+)+)/'), [
51
            'context'  => Validator::everywhere(),
52
            'priority' => 2,
53
            'factory'  => new TokenFactory(MetaToken::class)
54
        ]));
55
56
        $this->rules->add('meta.declaration.media', new Rule(new RegexMatcher('/@media(.*?)/'), [
57
            'context' => Validator::everywhere(),
58
            'factory' => new TokenFactory(MetaToken::class)
59
        ]));
60
61
        $this->rules->add('symbol.selector.tag', new Rule(new RegexMatcher('/([\w-]+)/'), [
62
            'context' => ['meta.selector', '!symbol', '!meta.declaration.media'],
63
        ]));
64
65
        $this->rules->rule('symbol.selector.class')->setContext(['meta.selector']);
66
        $this->rules->rule('symbol.selector.class.pseudo')->setContext(['meta.selector']);
67
        $this->rules->rule('symbol.selector.id')->setContext(['meta.selector']);
68
    }
69
70
    public function getIdentifier()
71
    {
72
        return 'sass';
73
    }
74
}
75