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

violinist-dev / project-data / 10132601105

28 Jul 2024 02:49PM UTC coverage: 79.545% (+0.06%) from 79.487%
10132601105

Pull #1

github

web-flow
Update composer.json
Pull Request #1: Use dotenv for parsing env string, and add method for getting as array

3 of 5 new or added lines in 1 file covered. (60.0%)

6 existing lines in 1 file now uncovered.

35 of 44 relevant lines covered (79.55%)

4.25 hits per line

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

79.55
/src/ProjectData.php
1
<?php
2

3
namespace Violinist\ProjectData;
4

5
use eiriksm\CosyComposer\Message;
6
use Symfony\Component\Dotenv\Dotenv;
7

8
class ProjectData
9
{
10

11
    /**
12
     * The nid.
13
     *
14
     * @var int
15
     */
16
    protected $nid;
17

18
    /**
19
     * The php version.
20
     *
21
     * @var string
22
     */
23
    protected $phpVersion;
24

25
    /**
26
     * @var string
27
     */
28
    protected $customPrMessage;
29

30
    /**
31
     * Roles for the project, inherited from the user.
32
     *
33
     * @var array
34
     */
35
    protected $roles;
36

37
    /**
38
     * Should we update all?
39
     *
40
     * @var bool
41
     */
42
    protected $updateAll;
43

44
    /**
45
     * Either a path to a directory (without the last slash) or null (means root).
46
     *
47
     * @var string|null
48
     */
49
    protected $composerJsonDir;
50

51
    /**
52
     * ENV string.
53
     *
54
     * @var string
55
     */
56
    protected $envString;
57

58
    /**
59
     * @return string
60
     */
61
    public function getEnvString()
62
    {
63
        return $this->envString;
7✔
64
    }
65

66
    public function getEnvArray() : array
67
    {
68
        $env = $this->getEnvString();
1✔
69
        $dotenv_data = new Dotenv();
1✔
70
        try {
71
            return $dotenv_data->parse($env);
1✔
NEW
72
        } catch (\Throwable $e) {
×
NEW
73
            return [];
×
74
        }
75
    }
76

77
    /**
78
     * @param string $envString
79
     */
80
    public function setEnvString($envString)
81
    {
82
        $this->envString = $envString;
7✔
83
    }
84

85
    /**
86
     * @return string|null
87
     */
88
    public function getComposerJsonDir()
89
    {
UNCOV
90
        return $this->composerJsonDir;
×
91
    }
92

93
    /**
94
     * @param string|null $composerJsonDir
95
     */
96
    public function setComposerJsonDir($composerJsonDir)
97
    {
UNCOV
98
        $this->composerJsonDir = $composerJsonDir;
×
99
    }
100

101
    /**
102
     * @return array
103
     */
104
    public function getRoles()
105
    {
106
        return $this->roles;
1✔
107
    }
108

109
    /**
110
     * @param array $roles
111
     */
112
    public function setRoles($roles)
113
    {
114
        $this->roles = $roles;
7✔
115
    }
116

117
    /**
118
     * @return string
119
     */
120
    public function getCustomPrMessage()
121
    {
122
        return $this->customPrMessage;
8✔
123
    }
124

125
    /**
126
     * @param string $customPrMessage
127
     */
128
    public function setCustomPrMessage($customPrMessage)
129
    {
130
        $this->customPrMessage = $customPrMessage;
4✔
131
    }
132

133
    /**
134
     * Get the nid.
135
     *
136
     * @return int
137
     *   Nid.
138
     */
139
    public function getNid()
140
    {
141
        return $this->nid;
6✔
142
    }
143

144
    public function shouldUpdateAll()
145
    {
UNCOV
146
        return $this->updateAll;
×
147
    }
148

149
    /**
150
     * Set the nid.
151
     *
152
     * @param int $nid
153
     *   A nid.
154
     */
155
    public function setNid($nid)
156
    {
157
        $this->nid = $nid;
7✔
158
    }
159

160
    /**
161
     * Get the php version.
162
     *
163
     * @return string
164
     *   The php version.
165
     */
166
    public function getPhpVersion()
167
    {
168
        return $this->phpVersion;
5✔
169
    }
170

171
    /**
172
     * Set the php version.
173
     *
174
     * @param string $phpVersion
175
     *   The php version.
176
     */
177
    public function setPhpVersion($phpVersion)
178
    {
179
        $this->phpVersion = $phpVersion;
7✔
180
    }
181

182
    /**
183
     * Set the update all flag.
184
     */
185
    public function setUpdateAll($update)
186
    {
UNCOV
187
        $this->updateAll = (bool) $update;
×
188
    }
189

190
    /**
191
     * Create an object from a node.
192
     *
193
     * @param \Drupal\node\NodeInterface $node
194
     *   A node.
195
     *
196
     * @return \Violinist\ProjectData\ProjectData
197
     *   A new project.
198
     */
199
    public static function fromNode($node)
200
    {
201
        $p = new self();
7✔
202
        $p->setNid($node->id());
7✔
203
        $p->setPhpVersion('7.0');
7✔
204
        if ($node->hasField('field_pull_request_template') && !$node->get('field_pull_request_template')->isEmpty()) {
7✔
205
            $p->setCustomPrMessage($node->get('field_pull_request_template')->first()->getString());
2✔
206
        }
207
        if (!$p->getCustomPrMessage()) {
7✔
208
            // See if we have a default one on the user.
209
            $owner = $node->getOwner();
5✔
210
            if ($owner->hasField('field_user_pr_template') && !$owner->get('field_user_pr_template')->isEmpty()) {
5✔
211
                $p->setCustomPrMessage($owner->get('field_user_pr_template')->first()->getString());
1✔
212
            }
213
        }
214
        if ($node->hasField('field_php_version') && !$node->get('field_php_version')->isEmpty()) {
7✔
215
            $p->setPhpVersion($node->get('field_php_version')->first()->getString());
1✔
216
        }
217
        if ($node->hasField('field_composer_json_path') && !$node->get('field_composer_json_path')->isEmpty()) {
7✔
218
            $directory = $node->get('field_composer_json_path')->first()->getString();
×
UNCOV
219
            $p->setComposerJsonDir($directory);
×
220
        }
221
        $owner = $node->getOwner();
7✔
222
        if ($owner) {
7✔
223
            $p->setRoles($owner->getRoles());
7✔
224
        }
225
        $p->setEnvString('');
7✔
226
        if ($node->hasField('field_environment_variables') && !$node->get('field_environment_variables')->isEmpty()) {
7✔
227
            $p->setEnvString($node->get('field_environment_variables')->first()->getString());
1✔
228
        }
229
        if (!$p->getEnvString()) {
7✔
230
            // Use the user one. If available.
231
            if ($owner) {
6✔
232
                if ($owner->hasField('field_environment_variables') && !$owner->get('field_environment_variables')->isEmpty()) {
6✔
UNCOV
233
                    $p->setEnvString($owner->get('field_environment_variables')->first()->getString());
×
234
                }
235
            }
236
        }
237
        return $p;
7✔
238
    }
239
}
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