From 22819ea8cec7d2f3d1613c7f469b5aee6f5e2cc4 Mon Sep 17 00:00:00 2001
From: Marius Burkard <m.burkard@pixcept.de>
Date: Tue, 9 Jun 2020 13:23:57 +0200
Subject: [PATCH] - added custom ci lint script

---
 .git-scripts/syntax.sh | 56 ++++++++++++++++++++++++++++++++++++++++++
 .gitlab-ci.yml         | 34 ++++++++++++++++++++++---
 2 files changed, 87 insertions(+), 3 deletions(-)
 create mode 100644 .git-scripts/syntax.sh

diff --git a/.git-scripts/syntax.sh b/.git-scripts/syntax.sh
new file mode 100644
index 0000000000..efc48ae4b3
--- /dev/null
+++ b/.git-scripts/syntax.sh
@@ -0,0 +1,56 @@
+#!/bin/bash
+
+IFS=$'\n'
+EX=0
+ERRS="" ;
+WARNS="" ;
+ERRCNT=0 ;
+WARNCNT=0 ;
+
+CMD="find . -type f \( -name \"*.php\" -o -name \"*.lng\" \) -print" ;
+
+if [[ "$1" == "commit" ]] ; then
+	CMD="git diff-tree --no-commit-id --name-only -r ${CI_COMMIT_SHA} | grep -E '\.(php|lng)$'" ;
+fi
+
+for F in $(eval "$CMD") ; do
+	if [[ ! -e "${F}" && -f "${F}" ]] ; then
+		continue ;
+	fi
+	echo -n "${F} ... " ;
+	R=$(php -d error_reporting=E_ALL -d display_errors=On -l "$F" 2>/dev/null) ;
+	RET=$? ;
+	R=$(echo "${R}" | sed "/^$/d")
+	if [ $RET -gt 0 ] ; then
+		EX=1 ;
+		echo "[ERROR]" ;
+		ERRS="${ERRS}${F}:"$'\n'"${R}"$'\n\n' ;
+		ERRCNT=$((ERRCNT + 1)) ;
+	else
+		if [[ "$R" == "Deprecated: "* ]] ; then
+			echo "[WARN]" ;
+			WARNS="${WARNS}${F}:"$'\n'"${R}"$'\n\n' ;
+			WARNCNT=$((WARNCNT + 1)) ;
+		else 
+			echo "[OK]" ;
+		fi
+	fi
+done
+
+echo ""
+echo "--------------------------";
+echo ""
+echo "${ERRCNT} Errors"
+if [ $ERRCNT -gt 0 ] ; then
+	echo "${ERRS}"
+	echo ""
+fi
+
+echo "${WARNCNT} Warnings"
+if [ $WARNCNT -gt 0 ] ; then
+	echo ""
+	echo "${WARNS}"
+	echo ""
+fi
+
+exit $EX
\ No newline at end of file
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index cdcc6edb29..4e4a201bfc 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -1,6 +1,7 @@
 # Defines stages which are to be executed
 stages:
   - syntax
+  - syntax_diff
 
 #
 ### Stage syntax
@@ -16,8 +17,35 @@ syntax:lint:
     - merge_requests
 
   script:
-    - composer require overtrue/phplint
     - echo "Syntax checking PHP files"
-    - echo "For more information http://www.icosaedro.it/phplint/"
-    - vendor/bin/phplint
+    - bash ./.git-scripts/syntax.sh
+
+
+syntax_diff:lint:
+  stage: syntax
+  image: edbizarro/gitlab-ci-pipeline-php:7.2
+  allow_failure: false
+  only:
+    - web
+    - pushes
+    - branches
+
+  script:
+    - echo "Syntax checking PHP files"
+    - bash ./.git-scripts/syntax.sh commit
+
+#syntax:lint:
+#  stage: syntax
+#  image: edbizarro/gitlab-ci-pipeline-php:7.2
+#  allow_failure: false
+#  only:
+#    - schedules
+#    - web
+#    - merge_requests
+#
+#  script:
+#    - composer require overtrue/phplint
+#    - echo "Syntax checking PHP files"
+#    - echo "For more information http://www.icosaedro.it/phplint/"
+#    - vendor/bin/phplint
 
-- 
GitLab