0

Laravel 5.1 has only one built-in hardcoded Mess Detection, it searches to see if @package tag is the same with /namespace, like so:

preg_match('/namespace\ ' . self::REQUIRED_NAMESPACE . '\\\(.*);/isU', $content, $namespace);
        preg_match('/\/*( )+@package\ (.*)[\r?\n]/isU', $content, $package);

        if (!isset($namespace[1]) || empty($namespace[1])) {
            continue;
        }

I want to extend this to add multiple detection classes. My folder structure currently looks like this:

Helpers >
    Commands >
        MessDetector >
            Detector >
                DetectorInterface.php
                DetectorAbstract.php
            PackageTagDetector.php
        MessDetector.php

The file MessDetector is made as an Artisan Command, that means it extends \Illuminate\Console\Command

I have a config file called mess_detection.php which has the detection rules like so:

return [
    'rules' => [
        '\Helpers\Commands\MessDetector\PackageTagDetector' =>
            [
                'rule' => '/\/*( )+@package\ (.*)[\r?\n]/isU',
                'path' => app_path(),
                'info' => 'Checking for @package tag',
                'error'=> 'Malformed or missing package tag'
            ]
        ]
    ];

But got stuck with figuring out how exactly to instantiate PackageTagDetector class in MessDetector class.

Any ideas design pattern wise?

4

2 回答 2

0

Laravel 没有内置的混乱检测器。检查包标签是否与命名空间匹配也是一个自定义约定,Laravel 根本不使用包标签。好像您正在使用第三方库?

于 2015-08-04T13:07:58.600 回答
0

我为我需要的每条规则创建了一个抽象类和接口。每个规则都有它自己的类。规则扩展了摘要,并在摘要中使用了大部分逻辑。规则本身存储在配置文件中,在配置文件中我还提到了类和特定于类的操作。

于 2015-08-09T18:06:42.070 回答