Code clone analysis of yiisoft

Did anyone attempt a code clone detection of the yiisoft vendor package after install? Just did it now, there are some results that might be interesting. Here’s one example:

  - yiiapp/vendor/yiisoft/error-handler/src/HeaderHelper.php:34-174 (141 lines)
    yiiapp/vendor/yiisoft/yii-web/src/Helper/HeaderHelper.php:7-147

I’m using an algorithm that is not finished yet, but even with phpcpd there are some results:

  - /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/yii-bulma/src/Modal.php:101-255 (154 lines)
    /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/yii-bulma/src/ModalCard.php:132-286

  - /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/error-handler/src/HeaderHelper.php:34-106 (72 lines)
    /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/yii-web/src/Helper/HeaderHelper.php:7-79

  - /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/cache/src/Dependency/AllDependencies.php:20-70 (50 lines)
    /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/cache/src/Dependency/AnyDependency.php:20-70

  - /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/error-handler/src/HeaderHelper.php:223-264 (41 lines)
    /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/yii-web/src/Helper/HeaderHelper.php:159-200

  - /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/error-handler/src/HeaderHelper.php:129-165 (36 lines)
    /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/yii-web/src/Helper/HeaderHelper.php:78-114

  - /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/yii-bulma/src/Modal.php:27-63 (36 lines)
    /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/yii-bulma/src/ModalCard.php:32-68

  - /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/html/src/Widget/CheckboxList/CheckboxList.php:204-239 (35 lines)
    /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/html/src/Widget/RadioList/RadioList.php:176-211

  - /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/yii-bulma/src/Modal.php:27-55 (28 lines)
    /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/yii-bulma/src/ProgressBar.php:20-48

  - /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/di/tests/Unit/CompositePsrContainerOverYiisoftTest.php:48-66 (18 lines)
    /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/di/tests/Unit/ContainerTest.php:1380-1398

  - /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/router-fastroute/tests/UrlGeneratorTest.php:129-145 (16 lines)
    /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/router/tests/GroupTest.php:214-230

  - /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/yii-bulma/src/Modal.php:300-316 (16 lines)
    /home/olle/kod/suffixtree/yiiapp/vendor/yiisoft/yii-bulma/src/ModalCard.php:478-494

tests/ need to be exluded from the search. Might have time to refine it a bit.

These two functions are almost identical too:

  - yiiapp/vendor/yiisoft/html/src/Tag/Base/BooleanInputTag.php:109-128 (20 lines)
    yiiapp/vendor/yiisoft/html/src/Tag/Select.php:249-268

A successful strategy to remove such duplicates could be to think more in traits, perhaps?

I did. Traits aren’t a good strategy to remove code duplication because, in fact, they do not remove duplication but making it look “good” (in fact just cryptic).

1 Like

Alright! May I ask which tool you used?

I’ve used PhpStorm’s built-in analysis for detection.

Got it! I think that’s a Type 2 detection algorithm.

Description of my patch to phpcpd: Evaluating a Type 3 code clone detection algorithm for PHP