Completed
Push — master ( 8bdd42...ce9a8f )
by cam
05:11
created

Spip_Css_Vars_Collection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 19
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 3 1
A getString() 0 7 2
A __toString() 0 3 1
1
<?php
2
3
/**
4
 * Collection de variables CSS
5
 * @internal
6
 */
7
class Spip_Css_Vars_Collection {
8
    private $vars = [];
9
10
    public function add(string $var, string $value) {
11
        $this->vars[$var] = $value;
12
    }
13
14
    public function getString() : string {
15
        $string = "";
16
        foreach ($this->vars as $key => $value) {
17
            $string .= "$key: $value;\n";
18
        }
19
        return $string;
20
    }
21
22
    public function __toString() {
23
        return $this->getString();
24
    }
25
}
26
27
/**
28
 * Génère les variables CSS d'une couleur pour l'espace privé
29
 *
30
 * @param string $couleur Couleur hex
31
 * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be Spip_Css_Vars_Collection?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
32
 */
33
function spip_couleur_theme_generer_variables_css($couleur) : \Spip_Css_Vars_Collection {
34
35
    $vars = new \Spip_Css_Vars_Collection();
36
37
    $vars->add("--spip-color-theme--hsl", couleur_hex_to_hsl($couleur, "h, s, l"));
38
    $vars->add("--spip-color-theme--rgb", couleur_hex_to_rgb($couleur, "r, g, b"));
39
40
    $vars->add("--spip-color-theme--h", couleur_hex_to_hsl($couleur, "h"));
41
    $vars->add("--spip-color-theme--s", couleur_hex_to_hsl($couleur, "s"));
42
    $vars->add("--spip-color-theme--l", couleur_hex_to_hsl($couleur, "l"));
43
    $vars->add("--spip-color-theme--r", couleur_hex_to_rgb($couleur, "r")); // utile ?
44
    $vars->add("--spip-color-theme--g", couleur_hex_to_rgb($couleur, "g")); // utile ?
45
    $vars->add("--spip-color-theme--b", couleur_hex_to_rgb($couleur, "b")); // utile ?
46
47
    // un joli dégradé de presque blanc à presque noir…
48
    $vars->add("--spip-color-theme--100", '#' . couleur_eclaircir($couleur, .99));
49
    $vars->add("--spip-color-theme--98", '#' . couleur_eclaircir($couleur, .95));
50
    $vars->add("--spip-color-theme--95", '#' . couleur_eclaircir($couleur, .90));
51
    $vars->add("--spip-color-theme--90", '#' . couleur_eclaircir($couleur, .75));
52
    $vars->add("--spip-color-theme--80", '#' . couleur_eclaircir($couleur, .50));
53
    $vars->add("--spip-color-theme--70", '#' . couleur_eclaircir($couleur, .25));
54
    $vars->add("--spip-color-theme--60", $couleur);
55
    $vars->add("--spip-color-theme--50", '#' . couleur_foncer($couleur, .125));
56
    $vars->add("--spip-color-theme--40", '#' . couleur_foncer($couleur, .25));
57
    $vars->add("--spip-color-theme--30", '#' . couleur_foncer($couleur, .375));
58
    $vars->add("--spip-color-theme--20", '#' . couleur_foncer($couleur, .50));
59
    $vars->add("--spip-color-theme--10", '#' . couleur_foncer($couleur, .75));
60
    $vars->add("--spip-color-theme--00", '#' . couleur_foncer($couleur, .98));
61
62
    // nos déclinaisons (basées sur le dégradé précedent, où 60 est là couleur du thème)
63
    $vars->add("--spip-color-theme-white", "var(--spip-color-theme--100)");
64
    $vars->add("--spip-color-theme-lightest", "var(--spip-color-theme--95)");
65
    $vars->add("--spip-color-theme-lighter", "var(--spip-color-theme--90)");
66
    $vars->add("--spip-color-theme-light", "var(--spip-color-theme--80)");
67
    $vars->add("--spip-color-theme", "var(--spip-color-theme--60)");
68
    $vars->add("--spip-color-theme-dark", "var(--spip-color-theme--40)");
69
    $vars->add("--spip-color-theme-darker", "var(--spip-color-theme--20)");
70
    $vars->add("--spip-color-theme-darkest", "var(--spip-color-theme--10)");
71
    $vars->add("--spip-color-theme-black", "var(--spip-color-theme--00)");
72
73
    return $vars;
74
}