• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

Cecilapp / Cecil / 5046064611

pending completion
5046064611

push

github

GitHub
perf: native_function_invocation (#1697)

322 of 322 new or added lines in 62 files covered. (100.0%)

2784 of 4121 relevant lines covered (67.56%)

0.68 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.22
/src/Renderer/Language.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of Cecil.
7
 *
8
 * Copyright (c) Arnaud Ligny <arnaud@ligny.fr>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13

14
namespace Cecil\Renderer;
15

16
use Cecil\Config;
17
use Cecil\Exception\RuntimeException;
18

19
/**
20
 * Class Language.
21
 */
22
class Language
23
{
24
    /** @var Config */
25
    protected $config;
26

27
    /** @var string Current language. */
28
    protected $language;
29

30
    public function __construct(Config $config, string $language = null)
31
    {
32
        $this->config = $config;
1✔
33
        $this->language = $language;
1✔
34
        if ($language === null) {
1✔
35
            $this->language = $this->config->getLanguageDefault();
×
36
        }
37
    }
38

39
    /**
40
     * Returns the current language.
41
     *
42
     * @return string
43
     */
44
    public function __toString()
45
    {
46
        return $this->language;
1✔
47
    }
48

49
    /**
50
     * Returns the name of the current or of the given language code.
51
     */
52
    public function getName(?string $language = null): ?string
53
    {
54
        if ($language !== null) {
1✔
55
            $this->language = $language;
×
56
        }
57
        if ($this->hasProperty('name')) {
1✔
58
            return $this->config->getLanguageProperty('name', $this->language);
1✔
59
        }
60

61
        return null;
×
62
    }
63

64
    /**
65
     * Returns the locale of the current or of the given language code.
66
     */
67
    public function getLocale(?string $language = null): ?string
68
    {
69
        if ($language !== null) {
1✔
70
            $this->language = $language;
×
71
        }
72
        if ($this->hasProperty('locale')) {
1✔
73
            return $this->config->getLanguageProperty('locale', $this->language);
1✔
74
        }
75

76
        return null;
×
77
    }
78

79
    /**
80
     * Returns the weight of the current or of the given language code.
81
     */
82
    public function getWeight(?string $language = null): int
83
    {
84
        if ($language !== null) {
1✔
85
            $this->language = $language;
×
86
        }
87

88
        return $this->config->getLanguageIndex($this->language);
1✔
89
    }
90

91
    /**
92
     * Checks if the given property exists for the current language.
93
     */
94
    private function hasProperty(string $property): bool
95
    {
96
        $value = $this->config->getLanguageProperty($property, $this->language);
1✔
97

98
        if (empty($value)) {
1✔
99
            $language = $this->language ?: $this->config->getLanguageDefault();
×
100

101
            throw new RuntimeException(sprintf('The property "%s" is empty for language "%s".', $property, $language));
×
102
        }
103

104
        return true;
1✔
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc