Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
71.43% covered (warning)
71.43%
10 / 14
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
FlysystemBackCompatTrait
71.43% covered (warning)
71.43%
10 / 14
0.00% covered (danger)
0.00%
0 / 2
10.89
0.00% covered (danger)
0.00%
0 / 1
 directoryExists
90.91% covered (success)
90.91%
10 / 11
0.00% covered (danger)
0.00%
0 / 1
6.03
 has
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
12
1<?php
2
3namespace BrianHenryIE\Strauss\Helpers;
4
5use Elazar\Flystream\StripProtocolPathNormalizer;
6use League\Flysystem\FileAttributes;
7use League\Flysystem\WhitespacePathNormalizer;
8
9/**
10 * @see FlysystemBackCompatInterface
11 */
12trait FlysystemBackCompatTrait
13{
14
15    // Some version of Flysystem has:
16    // directoryExists
17    public function directoryExists(string $location): bool
18    {
19        if (method_exists($this, 'normalizePath')) {
20            $location = $this->normalizePath($location);
21        }
22
23        if (method_exists($this->flysystem, 'directoryExists')) {
24            return $this->flysystem->directoryExists($location);
25        }
26
27        $parentDirectoryContents = $this->listContents(dirname($location));
28        /** @var FileAttributes $entry */
29        foreach ($parentDirectoryContents as $entry) {
30            if ($entry->path() == $location) {
31                return $entry->isDir();
32            }
33        }
34
35        /**
36         * Flysystem is ignoring symlinks.
37         * A better implementation of this fix is done in another branch which will be merged in #278.
38         */
39        if (is_dir("/$location")) {
40            return true;
41        }
42
43        return false;
44    }
45
46    // Some version of Flysystem has:
47    // has
48    public function has(string $location): bool
49    {
50        if (method_exists($this->flysystem, 'has')) {
51            return $this->flysystem->has($location);
52        }
53        return $this->fileExists($location) || $this->directoryExists($location);
54    }
55}