Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
VersionCheckResult
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
5 / 5
5
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getCurrentVersion
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getLatestVersion
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isOutdated
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 normalize
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5/**
6 * Fast Forward Development Tools for PHP projects.
7 *
8 * This file is part of fast-forward/dev-tools project.
9 *
10 * @author   Felipe SayĆ£o Lobato Abreu <github@mentordosnerds.com>
11 * @license  https://opensource.org/licenses/MIT MIT License
12 *
13 * @see      https://github.com/php-fast-forward/
14 * @see      https://github.com/php-fast-forward/dev-tools
15 * @see      https://github.com/php-fast-forward/dev-tools/issues
16 * @see      https://php-fast-forward.github.io/dev-tools/
17 * @see      https://datatracker.ietf.org/doc/html/rfc2119
18 */
19
20namespace FastForward\DevTools\SelfUpdate;
21
22/**
23 * Describes the installed and latest known DevTools versions.
24 */
25  class VersionCheckResult
26{
27    /**
28     * @param string $currentVersion the currently installed DevTools version
29     * @param string $latestVersion the latest stable DevTools version known to Composer
30     */
31    public function __construct(
32        private string $currentVersion,
33        private string $latestVersion,
34    ) {}
35
36    /**
37     * Returns the currently installed DevTools version.
38     */
39    public function getCurrentVersion(): string
40    {
41        return $this->currentVersion;
42    }
43
44    /**
45     * Returns the latest stable DevTools version known to Composer.
46     */
47    public function getLatestVersion(): string
48    {
49        return $this->latestVersion;
50    }
51
52    /**
53     * Detects whether the installed version is older than the latest stable version.
54     */
55    public function isOutdated(): bool
56    {
57        return version_compare($this->normalize($this->currentVersion), $this->normalize($this->latestVersion), '<');
58    }
59
60    /**
61     * Normalizes common Composer tag prefixes before version comparison.
62     *
63     * @param string $version the version string returned by Composer metadata
64     */
65    private function normalize(string $version): string
66    {
67        return ltrim($version, 'v');
68    }
69}