File names, sorted. * * @throws RuntimeException When the directory cannot be listed. */ function find_baselines( string $directory ): array { $entries = is_dir( $directory ) ? scandir( $directory ) : false; if ( false === $entries ) { throw new RuntimeException( "Could not list the PHPStan baselines in $directory." ); } $names = array(); foreach ( $entries as $name ) { if ( '' !== $name && 1 === preg_match( BASELINE_FILE_PATTERN, $name ) ) { $names[] = $name; } } return $names; } /** * Returns the configuration a baselines loader hands to PHPStan. * * Each baseline is included by its bare file name, which PHPStan resolves against * the loader's path as the configuration reached it. A loader's __DIR__ is the * real path, with any symbolic link resolved, so an absolute path built from it * would place the baselines, and the paths their entries name relative to * themselves, outside a checkout reached through a link, where they match none * of the analyzed files. * * @param non-empty-string $directory The loader's directory, as its __DIR__. * @return array{includes: list} Configuration. * * @throws RuntimeException When the directory cannot be listed. */ function get_baseline_includes( string $directory ): array { if ( getenv( GENERATING_BASELINES_ENV ) === $directory ) { return array( 'includes' => array() ); } return array( 'includes' => find_baselines( $directory ) ); }