| Conditions | 3 |
| Paths | 4 |
| Total Lines | 29 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 17 |
| CRAP Score | 3 |
| Changes | 0 | ||
| 1 | <?php |
||
| 34 | 7 | public function __invoke(string $path) : string |
|
| 35 | { |
||
| 36 | 7 | $templatePath = __DIR__ . '/../usage-finder-psalm.xml.template'; |
|
| 37 | |||
| 38 | 7 | $tmpPath = tempnam(sys_get_temp_dir(), 'usage-finder-psalm') . '.xml'; |
|
| 39 | |||
| 40 | 7 | $vendorPath = null; |
|
| 41 | |||
| 42 | 7 | if (file_exists($path . '/vendor')) { |
|
| 43 | 5 | $vendorPath = 'vendor'; |
|
| 44 | } |
||
| 45 | |||
| 46 | 7 | $codePath = (new GuessCodePath())->__invoke($path) ?? $path; |
|
| 47 | |||
| 48 | 7 | $directoryXml = sprintf(self::DIRECTORY_XML, $codePath); |
|
| 49 | 7 | $ignoreFilesXml = $vendorPath !== null ? sprintf(self::IGNORE_FILES_XML, $vendorPath) : ''; |
|
| 50 | |||
| 51 | 7 | $projectFilesXml = str_replace( |
|
| 52 | 7 | ['{{ directoryXml }}', '{{ ignoreFilesXml }}'], |
|
| 53 | 7 | [$directoryXml, $ignoreFilesXml], |
|
| 54 | 7 | self::PROJECT_FILES_XML |
|
| 55 | ); |
||
| 56 | |||
| 57 | 7 | $configXml = file_get_contents($templatePath); |
|
| 58 | 7 | $configXml = str_replace('{{ projectFilesXml }}', $projectFilesXml, $configXml); |
|
| 59 | |||
| 60 | 7 | file_put_contents($tmpPath, $configXml); |
|
| 61 | |||
| 62 | 7 | return $tmpPath; |
|
| 63 | } |
||
| 65 |