. * @author niel * @copyright 2015 nZEDb */ namespace app\extensions\qa\rules\syntax; class HasCorrectPermissions extends \li3_quality\qa\rules\syntax\HasCorrectPermissions { /** * @var array Specific permissions allowed for specified file suffixes. */ public $permsAllowed = [ 'php' => '775', ]; /** * @var string Default permissions for unspecified file suffixes. */ public $permsDefault = '644'; public function apply($testable, array $config = []) { $suffix = pathinfo($testable->config('path'), PATHINFO_EXTENSION); $message = "Permissions for '.%s' files should be '%s', found '%s'."; $permsFound = substr(sprintf('%o', fileperms($testable->config('path'))), -3); $permsAllowed = array_key_exists($suffix, $this->permsAllowed) ? $this->permsAllowed[$suffix] : $this->permsDefault; if (!preg_match("#$permsAllowed#", $permsFound)) { $this->addViolation([ 'message' => sprintf( $message, $suffix, $permsAllowed, $permsFound ) ]); } } } ?>