|
| 1 | +#!/usr/bin/env php |
| 2 | +<?php |
| 3 | + |
| 4 | +if ($argc !== 3) { |
| 5 | + echo "./docs-invalid-use.php path-to-docs path-to-symfony\n"; |
| 6 | + exit(1); |
| 7 | +} |
| 8 | + |
| 9 | +// Input |
| 10 | +$docs = $argv[1]; |
| 11 | +$symfony = $argv[2]; |
| 12 | + |
| 13 | +$autoload = [ |
| 14 | + __DIR__.'/vendor/autoload.php', |
| 15 | + $symfony.'/vendor/autoload.php', |
| 16 | +]; |
| 17 | + |
| 18 | +foreach ($autoload as $autoloadPHP) { |
| 19 | + if (!file_exists($autoloadPHP)) { |
| 20 | + echo "File $autoloadPHP does not exist.\nMake sure to run 'composer update'\n"; |
| 21 | + exit(1); |
| 22 | + } |
| 23 | + require $autoloadPHP; |
| 24 | +} |
| 25 | + |
| 26 | +use Symfony\Component\Finder\Finder; |
| 27 | +$finder = new Finder(); |
| 28 | +$finder->in($docs)->name('*.rst'); |
| 29 | + |
| 30 | +$blocklist = getBlocklist(); |
| 31 | +$count = 0; |
| 32 | +foreach ($finder as $file) { |
| 33 | + $contents = $file->getContents(); |
| 34 | + $matches = []; |
| 35 | + if (preg_match_all('|^ +use (.*\\\.*); *?$|im', $contents, $matches)) { |
| 36 | + foreach ($matches[1] as $class) { |
| 37 | + if (substr($class, 0, 3) === 'App' || substr($class, 0, 4) === 'Acme') { |
| 38 | + continue; |
| 39 | + } |
| 40 | + |
| 41 | + if (false !== $pos = strpos($class, ' as ')) { |
| 42 | + $class = substr($class, 0, $pos); |
| 43 | + } |
| 44 | + |
| 45 | + if (false !== $pos = strpos($class, 'function ')) { |
| 46 | + continue; |
| 47 | + } |
| 48 | + |
| 49 | + if (in_array($class, $blocklist)) { |
| 50 | + continue; |
| 51 | + } |
| 52 | + |
| 53 | + $explode = explode('\\', $class); |
| 54 | + if (count($explode) === 3 && $explode[0] === 'Symfony' && $explode[1] === 'Component') { |
| 55 | + continue; |
| 56 | + } |
| 57 | + |
| 58 | + if (!class_exists($class) && !interface_exists($class) && !trait_exists($class)) { |
| 59 | + $count++; |
| 60 | + echo $file->getRelativePath().'/'.$file->getFilename(). ' - '.$class. PHP_EOL; |
| 61 | + } |
| 62 | + } |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +if ($count === 0) { |
| 67 | + error_log("We found nothing\n"); |
| 68 | +} |
| 69 | + |
| 70 | +echo "foo".PHP_EOL; |
| 71 | +echo "bar".PHP_EOL; |
| 72 | + |
| 73 | +exit(0); |
| 74 | + |
| 75 | +function getBlocklist(): array |
| 76 | +{ |
| 77 | + return [ |
| 78 | + 'Doctrine\ORM\Mapping', |
| 79 | + 'Symfony\Component\Validator\Constraints', |
| 80 | + 'Simplex\StringResponseListener', |
| 81 | + 'Calendar\Model\LeapYear', |
| 82 | + 'Symfony\Component\Security\Core\Validator\Constraints', |
| 83 | + 'Simplex\Framework', |
| 84 | + 'Calendar\Controller\LeapYearController', |
| 85 | + 'ApiPlatform\Core\Annotation\ApiResource', |
| 86 | + 'Other\Qux', |
| 87 | + 'Doctrine\Bundle\FixturesBundle\Fixture', |
| 88 | + 'Vendor\DependencyClass', |
| 89 | + 'Example\Namespace\YourAwesomeCoolClass', |
| 90 | + 'Your\Transport\YourTransportFactory', |
| 91 | + ]; |
| 92 | +} |
0 commit comments