git的code_style.php
来源:互联网 发布:windows 启动管理器 编辑:程序博客网 时间:2024/05/17 06:39
这是为了规范上线代码自己写的一个php脚本,在这里做一下备份,以备不时之需。
<?php //获取提交的参数 $fp = fopen('php://stdin', 'r'); $input = fgets($fp); $params = explode(" ", $input); $old_commitid = isset($params[0]) ? $params[0] : ''; $commitid = isset($params[1]) ? $params[1] : ''; //这里是新创建分支的情况 if ($old_commitid == '0000000000000000000000000000000000000000') { $cmd = "git diff --cached --name-only $commitid"; $file_names = shell_exec($cmd); } else { $cmd = "git diff --name-only $commitid $old_commitid"; $file_names = shell_exec($cmd); } $files = explode("\n", $file_names); $phpcs_path = '/opt/codesniffer/vendor/bin'; $tmp_content_path = "/tmp/tmp_content.php"; $err_str = ''; if ($files) { foreach ($files as $_file) { $_file = ltrim($_file, 'remote:'); $_file = trim($_file); if (!empty($_file)) { if (filter_special($_file)) { continue; } $tmp_content = shell_exec("git show $commitid:$_file"); if (match_special($_file)) { $tmp_content = str_replace("<?php", "<?php\nnamespace testnamespace;", $tmp_content); } file_put_contents($tmp_content_path, $tmp_content); $cmd = '/opt/codesniffer/vendor/bin/phpcs /tmp/tmp_content.php --standard=PSR2'; $verify_ret = shell_exec($cmd); $verify_ret = shell_exec("$phpcs_path/phpcs $tmp_content_path --standard=PSR2"); $verify_ret = str_replace("$tmp_content_path", "$_file", $verify_ret); $err_str .= $verify_ret; } } } if (file_exists($tmp_content_path)) { unlink($tmp_content_path); } echo $err_str;/** * 过滤特殊文件 * @param [type] $filepath [description] * @return [type] [description] */function filter_special($filepath) { if (empty($filepath)) { return true; } $special_str = [ 'Bootstrap.php', 'web/index.php', 'api/index.php', 'admin/index.php', 'client/index.php', 'seller/index.php', 'app/views', 'app/modules', 'app/plugins', 'app/source', 'README.md', 'web/conf/app.ini', 'library/helper', 'CMQ' ]; foreach ($special_str as $_special) { if (strpos($filepath, $_special) !== false) { return true; } } return false; }/** * 框架controller不能加namespace * [match_special description] * @param [type] $filepath [description] * @return [type] [description] */function match_special($filepath) { if (empty($filepath)) { return false; } $special_str = [ 'controllers', 'Controller.php', 'Index.php' ]; foreach ($special_str as $_special) { if (strpos($filepath, $_special) !== false) { return true; } } return false; }
阅读全文
0 0
- git的code_style.php
- PHP得到当前GIT分支的代码
- git管理在PhpStrom上写的php项目.
- 基于Jenkins + Git的PHP项目编译脚本
- PHP项目中composer和Git的组合使用
- 动手开发一个简易的 PHP for Git Server 第一章
- Git PHP提交
- php 项目GIT部署
- 【git】git的分支
- 【git】-git的特点
- 用git部署php站点
- 用git部署php站点
- [李景山php]Git命令行操作
- Jenkins+Git+PHP生成构建PHP项目的changelog以用于生成增量或减量打包发布
- git git bash git shell的区别
- 关于window下使用git管理php源码的环境配置问题
- PHP Yii框架中使用git进行版本控制的一下知识
- 动手开发一个简易的 PHP for Git Server 第二章
- 怎么搭建github的maven仓库
- java字符串大小写转换
- 构造函数的继承
- 【无用】随笔—-摘抄170828
- 【XSY1728】【BZOJ3771】Triple 生成函数 FFT 容斥原理
- git的code_style.php
- poj1469 二分图最大匹配 匈牙利算法BFS实现
- vscode root 权限运行
- python迭代器实例
- android 类似selector
- 使用web service访问biee报表数据
- TypeScript学习笔记(一)
- java开发中常见的各种插件、工具、jar版本的查看方法
- 数据结构--冒泡排序(BubbleSort)思想与实现