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

violinist-dev / project-data / 15740597247

18 Jun 2025 06:22PM UTC coverage: 72.917% (+0.4%) from 72.549%
15740597247

Pull #9

github

eiriksm
Remove the user env vars
Pull Request #9: Remove the user env vars

35 of 48 relevant lines covered (72.92%)

3.9 hits per line

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

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

3
namespace Violinist\ProjectData;
4

5
use Drupal\violinist_projects\ProjectNode;
6
use Drupal\violinist_teams\TeamNode;
7
use Symfony\Component\Dotenv\Dotenv;
8

9
class ProjectData
10
{
11

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

191
    /**
192
     * Create an object from a node.
193
     *
194
     * @param \Drupal\violinist_projects\ProjectNode $node
195
     *   A project node.
196
     *
197
     * @return \Violinist\ProjectData\ProjectData
198
     *   A new project.
199
     */
200
    public static function fromNode($node)
201
    {
202
        $p = new self();
7✔
203
        $p->setNid($node->id());
7✔
204
        $p->setPhpVersion('7.0');
7✔
205
        if ($node->hasField('field_pull_request_template') && !$node->get('field_pull_request_template')->isEmpty()) {
7✔
206
            $p->setCustomPrMessage($node->get('field_pull_request_template')->first()->getString());
2✔
207
        }
208
        if (!$p->getCustomPrMessage()) {
7✔
209
            // See if we have a default one on the team.
210
            $team = $node->getTeam();
5✔
211
            if ($team && $team->hasField('field_pull_request_template') && !$team->get('field_pull_request_template')->isEmpty()) {
5✔
212
                $p->setCustomPrMessage($team->get('field_pull_request_template')->first()->getString());
1✔
213
            }
214
        }
215
        if ($node->hasField('field_php_version') && !$node->get('field_php_version')->isEmpty()) {
7✔
216
            $p->setPhpVersion($node->get('field_php_version')->first()->getString());
1✔
217
        }
218
        if ($node->hasField('field_composer_json_path') && !$node->get('field_composer_json_path')->isEmpty()) {
7✔
219
            $directory = $node->get('field_composer_json_path')->first()->getString();
×
220
            $p->setComposerJsonDir($directory);
×
221
        }
222
        $owner = $node->getOwner();
7✔
223
        if ($owner) {
7✔
224
            $p->setRoles($owner->getRoles());
7✔
225
        }
226
        $p->setEnvString('');
7✔
227
        if ($node->hasField('field_environment_variables') && !$node->get('field_environment_variables')->isEmpty()) {
7✔
228
            $p->setEnvString($node->get('field_environment_variables')->first()->getString());
1✔
229
        }
230
        if (!$p->getEnvString()) {
7✔
231
            // The team one should really take precedence at this point. In fact,
232
            // we will remove the user one altogether at some point, but double
233
            // here is not the worst either.
234
            $team = $node->getTeam();
6✔
235
            if ($team instanceof TeamNode) {
6✔
236
                $new_env_string = '';
×
237
                foreach ($team->getEnvironmentVariables() as $key => $value) {
×
238
                    $new_env_string .= $key . '=' . $value . "\n";
×
239
                }
240
                if ($new_env_string) {
×
241
                    $p->setEnvString($new_env_string);
×
242
                }
243
            }
244
        }
245
        return $p;
7✔
246
    }
247
}
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

© 2025 Coveralls, Inc