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

JBZoo / Composer-Diff / 6408983532

16 Aug 2023 06:22PM UTC coverage: 94.294%. Remained the same
6408983532

push

github

web-flow
Upgrade `jbzoo/cli:^7.1.1` (#26)

1 of 1 new or added line in 1 file covered. (100.0%)

314 of 333 relevant lines covered (94.29%)

49.24 hits per line

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

96.67
/src/Renders/AbstractRender.php
1
<?php
2

3
/**
4
 * JBZoo Toolbox - Composer-Diff.
5
 *
6
 * This file is part of the JBZoo Toolbox project.
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 *
10
 * @license    MIT
11
 * @copyright  Copyright (C) JBZoo.com, All rights reserved.
12
 * @see        https://github.com/JBZoo/Composer-Diff
13
 */
14

15
declare(strict_types=1);
16

17
namespace JBZoo\ComposerDiff\Renders;
18

19
use JBZoo\ComposerDiff\Comparator;
20
use JBZoo\ComposerDiff\Diff;
21
use JBZoo\ComposerDiff\Exception;
22
use JBZoo\Data\Data;
23
use Symfony\Component\Console\Output\OutputInterface;
24

25
abstract class AbstractRender
26
{
27
    public const CONSOLE  = 'console';
28
    public const MARKDOWN = 'markdown';
29
    public const JSON     = 'json';
30

31
    /** @var Diff[] */
32
    protected array $fullChangeLog = [];
33
    protected string $env          = Comparator::ENV_BOTH;
34
    protected Data $params;
35

36
    /**
37
     * @param Diff[] $changeLog
38
     */
39
    abstract protected function renderOneEnv(OutputInterface $output, array $changeLog, string $env): void;
40

41
    public function __construct(array $params)
42
    {
43
        $this->params = new Data(
44✔
44
            \array_merge([
44✔
45
                'show-links'  => true,
44✔
46
                'strict-mode' => false,
44✔
47
            ], $params),
44✔
48
        );
44✔
49
    }
50

51
    /**
52
     * @param Diff[] $fullChangeLog
53
     */
54
    public function setFullChangeLog(array $fullChangeLog): self
55
    {
56
        $this->fullChangeLog = $fullChangeLog;
44✔
57

58
        return $this;
44✔
59
    }
60

61
    public function setEnv(string $env): self
62
    {
63
        $this->env = $env;
44✔
64

65
        return $this;
44✔
66
    }
67

68
    public function render(OutputInterface $output): bool
69
    {
70
        if (\count($this->fullChangeLog) === 0) {
44✔
71
            $output->writeln("There is no difference ({$this->env})");
8✔
72

73
            return false;
8✔
74
        }
75

76
        if (\in_array($this->env, [Comparator::ENV_BOTH, Comparator::ENV_PROD], true)) {
36✔
77
            $this->renderOneEnv($output, $this->fullChangeLog, Comparator::ENV_PROD);
32✔
78
        }
79

80
        if (\in_array($this->env, [Comparator::ENV_BOTH, Comparator::ENV_DEV], true)) {
36✔
81
            $this->renderOneEnv($output, $this->fullChangeLog, Comparator::ENV_DEV);
24✔
82
        }
83

84
        return true;
36✔
85
    }
86

87
    public static function factory(string $outputFormat, array $params): self
88
    {
89
        $outputFormat = \strtolower(\trim($outputFormat));
44✔
90

91
        if ($outputFormat === self::CONSOLE) {
44✔
92
            return new Console($params);
32✔
93
        }
94

95
        if ($outputFormat === self::MARKDOWN) {
16✔
96
            return new Markdown($params);
12✔
97
        }
98

99
        if ($outputFormat === self::JSON) {
8✔
100
            return new JsonOutput($params);
8✔
101
        }
102

103
        throw new Exception("Output format \"{$outputFormat}\" not found");
×
104
    }
105

106
    protected function showLinks(): bool
107
    {
108
        return (bool)$this->params->get('show-links');
32✔
109
    }
110

111
    /**
112
     * @phan-suppress PhanPluginPossiblyStaticProtectedMethod
113
     */
114
    protected function getTitle(string $env): string
115
    {
116
        return $env === Comparator::ENV_PROD
32✔
117
            ? 'PHP Production Dependencies'
28✔
118
            : 'PHP Dev Dependencies';
32✔
119
    }
120
}
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