ParallelizedComposerRepository::__debugInfo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 21
ccs 17
cts 17
cp 1
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
/*
3
 * hirak/prestissimo
4
 * @author Hiraku NAKANO
5
 * @license MIT https://github.com/hirak/prestissimo
6
 */
7
namespace Hirak\Prestissimo;
8
9
use Composer\Repository\ComposerRepository;
10
11
class ParallelizedComposerRepository extends ComposerRepository
12
{
13
    protected function preloadProviderListings($data)
14
    {
15
        if ($this->providersUrl && isset($data['provider-includes'])) {
16
            $includes = $data['provider-includes'];
17
18
            $requests = array();
19
            $cachedir = $this->config->get('cache-repo-dir');
20
            $cacheBase = $cachedir . DIRECTORY_SEPARATOR . strtr($this->baseUrl, ':/', '--');
21
            foreach ($includes as $include => $metadata) {
22
                $url = $this->baseUrl . '/' . str_replace('%hash%', $metadata['sha256'], $include);
23
                $cacheKey = str_replace(array('%hash%','$'), '', $include);
24
                if ($this->cache->sha256($cacheKey) !== $metadata['sha256']) {
25
                    $dest = $cacheBase . DIRECTORY_SEPARATOR . str_replace('/', '-', $cacheKey);
26
                    $requests[] = new CopyRequest($url, $dest, false, $this->io, $this->config);
27
                }
28
            }
29
            if ($requests) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $requests of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
30
                $prefetcher = new Prefetcher;
31
                $prefetcher->fetchAll($this->io, $requests);
32
            }
33
        }
34
    }
35
36
    public function prefetch()
37
    {
38
        if (null === $this->providerListing) {
39
            $this->preloadProviderListings($this->loadRootServerFile());
40
        }
41
    }
42
43 1
    public function __debugInfo()
44
    {
45
        return array(
46 1
            'url' => $this->url,
47 1
            'repoConfig' => $this->repoConfig,
48 1
            'options' => $this->options,
49 1
            'baseUrl' => $this->baseUrl,
50 1
            'notifyUrl' => $this->notifyUrl,
51 1
            'searchUrl' => $this->searchUrl,
52 1
            'hasProviders' => $this->hasProviders,
53 1
            'providersUrl' => $this->providersUrl,
54 1
            'lazyProvidersUrl' => $this->lazyProvidersUrl,
55 1
            'providerListing' => $this->providerListing,
56 1
            'providers' => $this->providers,
57 1
            'providersByUid' => $this->providersByUid,
58 1
            'rootAliases' => $this->rootAliases,
59 1
            'allowSslDowngrade' => $this->allowSslDowngrade,
60 1
            'sourceMirrors' => $this->sourceMirrors,
61 1
            'distMirrors' => $this->distMirrors,
62
        );
63
    }
64
}
65