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

mborne / remote-git / 14819670446

04 May 2025 09:05AM UTC coverage: 92.857%. Remained the same
14819670446

push

github

mborne
make fix-style...

455 of 490 relevant lines covered (92.86%)

3.08 hits per line

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

93.55
/src/Filter/ComposerProjectFilter.php
1
<?php
2

3
namespace MBO\RemoteGit\Filter;
4

5
use MBO\RemoteGit\ClientInterface as GitClientInterface;
6
use MBO\RemoteGit\Helper\LoggerHelper;
7
use MBO\RemoteGit\ProjectFilterInterface;
8
use MBO\RemoteGit\ProjectInterface;
9
use Psr\Log\LoggerInterface;
10

11
/**
12
 * Filter projects ensuring that composer.json is present. Optionally,
13
 * a project type can be forced.
14
 *
15
 * @author fantoine
16
 * @author mborne
17
 */
18
class ComposerProjectFilter implements ProjectFilterInterface
19
{
20
    /**
21
     * Client allowing to retrieve composer.json file.
22
     */
23
    protected GitClientInterface $gitClient;
24

25
    protected LoggerInterface $logger;
26

27
    /**
28
     * Filter according to composer project type ("library", "project",...).
29
     *
30
     * @see https://getcomposer.org/doc/04-schema.md#type
31
     */
32
    protected string $projectType;
33

34
    /**
35
     * ProjectTypeFilter constructor.
36
     */
37
    public function __construct(
38
        GitClientInterface $gitClient,
39
        ?LoggerInterface $logger = null,
40
    ) {
41
        $this->gitClient = $gitClient;
4✔
42
        $this->logger = LoggerHelper::handleNull($logger);
4✔
43
    }
44

45
    /**
46
     * Get filter according to project type.
47
     */
48
    public function getProjectType(): string
49
    {
50
        return $this->projectType;
×
51
    }
52

53
    /**
54
     * Set filter according to project type.
55
     */
56
    public function setProjectType(string $projectType): self
57
    {
58
        $this->projectType = $projectType;
3✔
59

60
        return $this;
3✔
61
    }
62

63
    public function getDescription(): string
64
    {
65
        $description = 'composer.json should exists';
1✔
66
        if (!empty($this->projectType)) {
1✔
67
            $description .= sprintf(" and type should be '%s'", $this->projectType);
1✔
68
        }
69

70
        return $description;
1✔
71
    }
72

73
    public function isAccepted(ProjectInterface $project): bool
74
    {
75
        try {
76
            $branch = $project->getDefaultBranch();
3✔
77
            if (is_null($branch)) {
3✔
78
                return false;
×
79
            }
80
            $json = $this->gitClient->getRawFile(
3✔
81
                $project,
3✔
82
                'composer.json',
3✔
83
                $branch
3✔
84
            );
3✔
85
            $composer = json_decode($json, true);
2✔
86
            if (empty($this->projectType)) {
2✔
87
                return true;
2✔
88
            }
89
            $types = array_map('strtolower', explode(',', $this->projectType));
2✔
90

91
            return isset($composer['type'])
2✔
92
                && in_array(strtolower($composer['type']), $types);
2✔
93
        } catch (\Exception $e) {
1✔
94
            $this->logger->debug(sprintf(
1✔
95
                '%s (branch %s) : file %s not found',
1✔
96
                $project->getName(),
1✔
97
                $project->getDefaultBranch(),
1✔
98
                'composer.json'
1✔
99
            ));
1✔
100

101
            return false;
1✔
102
        }
103
    }
104
}
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