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

sanmai / console / 15927767820

27 Jun 2025 01:42PM UTC coverage: 97.297% (-2.7%) from 100.0%
15927767820

Pull #6

github

web-flow
Merge 4afe2b2cb into 33fd65b55
Pull Request #6: Custom bootstrap script

10 of 11 new or added lines in 1 file covered. (90.91%)

36 of 37 relevant lines covered (97.3%)

6.7 hits per line

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

90.91
/src/ConfigLoader.php
1
<?php
2

3
/**
4
 * Copyright 2025 Alexey Kopytko <alexey@kopytko.com>
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 * http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18

19
declare(strict_types=1);
20

21
namespace ConsoleApp;
22

23
use Composer\InstalledVersions;
24
use SplFileObject;
25
use Composer\Autoload\ClassLoader;
26

27
use function json_decode;
28
use function spl_autoload_functions;
29
use function count;
30

31
use const JSON_THROW_ON_ERROR;
32

33
class ConfigLoader
34
{
35
    /** @var array{install_path: string} */
36
    private readonly array $rootPackage;
37

38
    /**
39
     * @param array{install_path: string}|null $rootPackage
40
     */
41
    public function __construct(
42
        readonly private ClassLoader $classLoader,
43
        ?array $rootPackage = null,
44
    ) {
45
        $this->rootPackage = $rootPackage ?? InstalledVersions::getRootPackage();
16✔
46
    }
47

48
    public function getBootstrapPath(): string
49
    {
50
        $path = $this->rootPackage['install_path'] . '/composer.json';
8✔
51
        $file = new SplFileObject($path, 'r');
8✔
52
        $json = json_decode($file->fread($file->getSize()), associative: true, flags: JSON_THROW_ON_ERROR);
8✔
53
        return $json['extra']['console']['bootstrap'] ?? '';
8✔
54
    }
55

56
    public function handleAutoloader(callable $callback): void
57
    {
58
        $beforeCount = $this->getAutoloaderCount();
4✔
59

60
        $callback();
4✔
61

62
        if ($this->getAutoloaderCount() <= $beforeCount) {
4✔
63
            return;
4✔
64
        }
65

66
        // If the autoloader was registered, we need to unregister it
NEW
67
        $this->classLoader->unregister();
×
68
    }
69

70
    public function getAutoloaderCount(): int
71
    {
72
        return count(spl_autoload_functions());
8✔
73
    }
74
}
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