function opml($args) { if (isset($args[0])) { $arg = array_shift($args); if ($arg == 'make') { $pods = []; $my_tags = $this->tags; foreach ($this->urls as $url => $data) { $matched = 0; foreach ($data['tags'] as $cast_tag) { if (in_array($cast_tag, $my_tags)) { $matched = 1; break; } } if ($matched) { $arr = ["url" => $url, "name" => $this->urls[$url]['name']]; $pods[] = $arr; echo "adding: {$arr['name']}\n"; } } ob_start(); include TEMPLATE_FILE; $opml = ob_get_clean(); file_put_contents(OPML_FILE, $opml); suc("Your opml.xml file is ready."); } } else { err("<opml make> is available."); } }
// @codingStandardsIgnoreFile $file = 'coverage.txt'; $minPercentage = isset($argv[1]) ? (int) $argv[1] : 30; if (!is_file($file)) { return err('未找到覆盖率文件"%s"', $file); } $content = file_get_contents($file); preg_match('/Lines:\\s+(.+?)%/', $content, $matches); if (!isset($matches[1])) { return err('未匹配到覆盖率数据'); } $percentage = $matches[1]; if ($percentage < $minPercentage) { return err('当前覆盖率(%s%%)过低,至少需要%s%%,请增加单元测试', $percentage, $minPercentage); } else { return suc('覆盖率是%s%%,达到要求的%s%%', $percentage, $minPercentage); } function suc($message, $args = null, $args2 = null) { $message = format(func_get_args()); echo $message . PHP_EOL; return ''; } function err($message, $args = null, $args2 = null) { $message = format(func_get_args()); echo $message . PHP_EOL; $dir = 'reports'; if (!is_dir($dir)) { mkdir($dir, 0777, true); }