token type constant // [1] => raw sytax parsed to that token // [2] => line number foreach ($tokens as $token) { // Since we only care about opening docblocks, // bail out when we get to the namespace token if (is_array($token) && $token[0] === T_NAMESPACE) { break; } if (is_array($token)) { $token = $token[1]; } $output .= $token; } return $output; } function get_tokens($source): array { return token_get_all($source); } function replace_files(array $files, $template): void { print_r($files); foreach ($files as $file) { $source = file_get_contents($file); if (stripos($source, 'namespace') === FALSE) { continue; } $tokens = get_tokens($source); $text_to_replace = get_text_to_replace($tokens); $header = file_get_contents(__DIR__ . $template); $new_text = "