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

heimrichhannot / contao-encore-bundle / 27198940069

09 Jun 2026 10:06AM UTC coverage: 75.679% (-1.9%) from 77.539%
27198940069

Pull #38

github

web-flow
Merge b0223807d into a10c8342e
Pull Request #38: Allow extension from App, various enhancements

28 of 68 new or added lines in 11 files covered. (41.18%)

3 existing lines in 2 files now uncovered.

641 of 847 relevant lines covered (75.68%)

2.27 hits per line

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

0.0
/src/EncoreExtension/EncoreExtensionWrapper.php
1
<?php
2

3
namespace HeimrichHannot\EncoreBundle\EncoreExtension;
4

5
use Composer\InstalledVersions;
6
use HeimrichHannot\EncoreContracts\EncoreExtensionInterface;
7
use Symfony\Component\Filesystem\Filesystem;
8
use Symfony\Component\HttpKernel\Bundle\BundleInterface;
9
use Symfony\Component\HttpKernel\KernelInterface;
10

11
class EncoreExtensionWrapper
12
{
13
    private BundleInterface $bundle;
14
    private \ReflectionClass $reflection;
15
    private string $bundlePath;
16

17
    public function __construct(
18
        public readonly EncoreExtensionInterface $extension,
19
        private readonly KernelInterface $kernel,
20
    ) {
NEW
21
    }
×
22

23
    private function getBundle(): BundleInterface
24
    {
NEW
25
        if (!isset($this->bundle)) {
×
NEW
26
            $this->bundle = $this->kernel->getBundles()[$this->getBundleShortName()];
×
27
        }
28

NEW
29
        return $this->bundle;
×
30
    }
31

32
    private function getReflection(): \ReflectionClass
33
    {
NEW
34
        if (!isset($this->reflection)) {
×
NEW
35
            $this->reflection = new \ReflectionClass($this->extension->getBundle());
×
36
        }
37

NEW
38
        return $this->reflection;
×
39
    }
40

41
    public function getBundlePath(): string
42
    {
NEW
43
        if (!isset($this->bundlePath)) {
×
NEW
44
            if ('App' === $this->extension->getBundle()) {
×
NEW
45
                return '.';
×
46
            }
47

NEW
48
            $bundlePath = $this->getBundle()->getPath();
×
NEW
49
            if (!file_exists($bundlePath . \DIRECTORY_SEPARATOR . 'composer.json')) {
×
NEW
50
                $bundlePath = $bundlePath . \DIRECTORY_SEPARATOR . '..';
×
51
            }
NEW
52
            if (!file_exists($bundlePath . \DIRECTORY_SEPARATOR . 'composer.json')) {
×
NEW
53
                throw new \RuntimeException('[Encore Bundle] Could not find composer.json file for ' . $this->getBundle()->getName() . '. Skipping EncoreExtension ' . $this->extension::class . '.');
×
54
            }
55

56
            try {
NEW
57
                $composerData = json_decode(file_get_contents($bundlePath . '/composer.json'), null, 512, \JSON_THROW_ON_ERROR);
×
NEW
58
            } catch (\JsonException) {
×
NEW
59
                throw new \JsonException('composer.json of ' . $this->getBundleShortName() . ' has a syntax error.');
×
60
            }
61

NEW
62
            $bundlePath = InstalledVersions::getInstallPath($composerData->name);
×
63

NEW
64
            $this->bundlePath = rtrim((new Filesystem())->makePathRelative($bundlePath, $this->kernel->getProjectDir()), \DIRECTORY_SEPARATOR);
×
65
        }
66

NEW
67
        return $this->bundlePath;
×
68
    }
69

70
    public function getBundleShortName(): string
71
    {
NEW
72
        if ('App' === $this->extension->getBundle()) {
×
NEW
73
            return 'App';
×
74
        }
75

NEW
76
        return $this->getReflection()->getShortName();
×
77
    }
78

79
    public function isAppExtension(): bool
80
    {
NEW
81
        return 'App' === $this->getBundleShortName();
×
82
    }
83
}
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