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

Cecilapp / Cecil / 5046041481

pending completion
5046041481

Pull #1697

github

GitHub
Merge 2cd309b47 into a16355c73
Pull Request #1697: perf: native_function_invocation

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

0.0
/src/Command/SelfUpdate.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\Command;
15

16
use Humbug\SelfUpdate\Updater;
17
use Symfony\Component\Console\Input\InputDefinition;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Input\InputOption;
20
use Symfony\Component\Console\Output\OutputInterface;
21

22
/**
23
 * Updates Cecil to the latest version.
24
 */
25
class SelfUpdate extends AbstractCommand
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    protected function configure()
31
    {
32
        $this
×
33
            ->setName('self-update')
×
34
            ->setDescription('Updates Cecil to the latest version')
×
35
            ->setDefinition(new InputDefinition([
×
36
                new InputOption('rollback', null, InputOption::VALUE_NONE, 'Revert to an older installation'),
×
37
                new InputOption('stable', null, InputOption::VALUE_NONE, 'Force an update to the last stable version'),
×
38
                new InputOption('preview', null, InputOption::VALUE_NONE, 'Force an update to the last unstable version'),
×
39
            ]))
×
40
            ->setHelp('The self-update command checks for a newer version and, if found, downloads and installs the latest');
×
41
    }
42

43
    /**
44
     * {@inheritdoc}
45
     */
46
    protected function execute(InputInterface $input, OutputInterface $output)
47
    {
48
        $version = $this->getApplication()->getVersion();
×
49

50
        $updater = new Updater(null, false, Updater::STRATEGY_GITHUB);
×
51

52
        // rollback
53
        if ($input->getOption('rollback')) {
×
54
            try {
55
                $result = $updater->rollback();
×
56
                if (!$result) {
×
57
                    $output->writeln('Rollback failed.');
×
58

59
                    return 1;
×
60
                }
61
                $output->writeln('Rollback done.');
×
62

63
                return 0;
×
64
            } catch (\Exception $e) {
×
65
                $output->writeln($e->getMessage());
×
66

67
                return 1;
×
68
            }
69
        }
70

71
        /** @var \Humbug\SelfUpdate\Strategy\GithubStrategy $strategy */
72
        $strategy = $updater->getStrategy();
×
73
        $strategy->setPackageName('cecil/cecil');
×
74
        $strategy->setPharName('cecil.phar');
×
75
        $strategy->setCurrentLocalVersion($version);
×
76
        $strategy->setStability($input->getOption('preview') ? 'unstable' : 'stable');
×
77
        $updater->setStrategyObject($strategy);
×
78

79
        try {
80
            $output->writeln('Checking for updates...');
×
81
            $result = $updater->update();
×
82
            if ($result) {
×
83
                $new = $updater->getNewVersion();
×
84
                $old = $updater->getOldVersion();
×
85
                $output->writeln(sprintf('Updated from <comment>%s</comment> to <info>%s</info>.', $old, $new));
×
86

87
                return 0;
×
88
            }
89
            $output->writeln(sprintf('You are already using the last version (<comment>%s</comment>).', $version));
×
90

91
            return 0;
×
92
        } catch (\Exception $e) {
×
93
            $output->writeln($e->getMessage());
×
94

95
            return 1;
×
96
        }
97
    }
98
}
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