#!/bin/bash

set -e

DIR=${1?Error: no extension dir given}
VENDOR_BIN=${2}

MAGENTO_PATH=$(cd $DIR/../../.. && pwd)
EXTENSION_PATH=$MAGENTO_PATH/vendor/algolia/algoliasearch-magento-2
THIS="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"

${VENDOR_BIN}magento2-update

PHP_COMPATIBILITY_PATH=$THIS/../vendor/phpcompatibility/php-compatibility

if [ ! -d "$PHP_COMPATIBILITY_PATH" ]; then
  PHP_COMPATIBILITY_PATH=$THIS/../phpcompatibility/php-compatibility
fi

${VENDOR_BIN}phpcs --config-set installed_paths $PHP_COMPATIBILITY_PATH

${VENDOR_BIN}phpcs -p --standard=PHPCompatibility --runtime-set testVersion 7.4- --runtime-set ignore_warnings_on_exit true --ignore=vendor/*,*/view $EXTENSION_PATH
