<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/using-jscpd-and-mago-to-fix-ai-generated-code-duplication-in-php-pmwfukgij" -->

---
title: Using jscpd and Mago to fix AI generated code...
description: AI coding agents often produce bloated code full of copy-pasted logic across controllers and models, creating maintenance headaches. The piece describes using...
canonical: https://daily.dev/posts/using-jscpd-and-mago-to-fix-ai-generated-code-duplication-in-php-pmwfukgij
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Using jscpd and Mago to fix AI generated code duplication in PHP | daily.dev
og:description: AI coding agents often produce bloated code full of copy-pasted logic across controllers and models, creating maintenance headaches. The piece describes using...
og:url: https://daily.dev/posts/using-jscpd-and-mago-to-fix-ai-generated-code-duplication-in-php-pmwfukgij
og:image: https://api.daily.dev/og/posts/pMwFUKGij.png
og:image:alt: Using jscpd and Mago to fix AI generated code duplication in PHP
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Using jscpd and Mago to fix AI generated code duplication in PHP

**[PHP Architect](https://daily.dev/sources/phparchitect)** · [@shocm](https://daily.dev/shocm) · 1 min read · 0 upvotes · 0 comments

## Summary

AI coding agents often produce bloated code full of copy-pasted logic across controllers and models, creating maintenance headaches. The piece describes using jscpd (a copy-paste detection tool) alongside Mago (a PHP tooling/linting tool) to have the AI agent detect and refactor its own duplicated code, turning code review from a chore into a feedback loop the agent can act on.

## Content

Video version: https://youtu.be/ubhVleOpLQ0 It’s so easy to ask an AI agent to build a feature, and have it hand you 5,000 lines of code. It might even feel like a win until you start reading it so see the same validation block in four controllers, the same database-fetch boilerplate in six models, and that efvery method wraps its logic in the same try/catch with the same log message. It “works,” but you now own a maintenance nightmare, and reviewing it drains the life out of your afternoon. LLMs are great at turning two sentences into thousands of lines of code, but that doesn’t mean it’s ...

https://www.phparch.com/2026/08/i-made-my-ai-agent-fix-its-own-copy-paste-jscpd-mago/

## Similar posts on daily.dev

- [Your Coding Agent Keeps Making the Same Mistakes. I Built a Fix](https://daily.dev/posts/your-coding-agent-keeps-making-the-same-mistakes-i-built-a-fix-6z2qgmuib) · Adventures in Nodeland · 0 upvotes · 0 comments
- [I Created a Code Graph of Magento 2 for AI Agents](https://daily.dev/posts/i-created-a-code-graph-of-magento-2-for-ai-agents-3jitcrppy) · Shaaf · 0 upvotes · 0 comments
- [I'm Building Agents That Run While I Sleep](https://daily.dev/posts/i-m-building-agents-that-run-while-i-sleep-psrvg5tk0) · Hacker News · 2 upvotes · 0 comments

---

Tags: [#php](https://daily.dev/tags/php), [#vibe-coding](https://daily.dev/tags/vibe-coding)

[View this post on daily.dev](https://daily.dev/posts/using-jscpd-and-mago-to-fix-ai-generated-code-duplication-in-php-pmwfukgij)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"DiscussionForumPosting","mainEntityOfPage":"https://daily.dev/posts/using-jscpd-and-mago-to-fix-ai-generated-code-duplication-in-php-pmwfukgij","headline":"Using jscpd and Mago to fix AI generated code duplication in PHP","text":"AI coding agents often produce bloated code full of copy-pasted logic across controllers and models, creating maintenance headaches. The piece describes using jscpd (a copy-paste detection tool) alongside Mago (a PHP tooling/linting tool) to have the AI agent detect and refactor its own duplicated code, turning code review from a chore into a feedback loop the agent can act on.","url":"https://daily.dev/posts/using-jscpd-and-mago-to-fix-ai-generated-code-duplication-in-php-pmwfukgij","datePublished":"2026-08-21T18:04:38.040Z","dateModified":"2026-08-21T18:30:55.107Z","author":{"@type":"Person","name":"Eric Johnson","url":"https://daily.dev/shocm","image":"https://media.daily.dev/image/upload/s--EPMJ-a-K--/f_auto/v1755890250/avatars/avatar_y7ct3dSEp45NFSALYHve6?_a=BAMClqZW0","description":"PHP Architect team member. I am powered by 16-year-old single malt Scotch and baseball.","worksFor":{"@type":"Organization","name":"php[architect]","logo":"https://res.cloudinary.com/daily-now/image/upload/s--10MwB_VH--/f_auto/v1726147436/companies/phparch"},"interactionStatistic":{"@type":"InteractionCounter","interactionType":{"@type":"EndorseAction"},"userInteractionCount":400}},"image":"https://media.daily.dev/image/upload/s--oNAJlgpk--/f_auto/v1787337054/posts/pMwFUKGij?_a=BAMAMicg0","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"isPartOf":{"@type":"WebPage","url":"https://daily.dev/squads/phparchitect","name":"PHP Architect"}}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"PHP Architect","item":"https://daily.dev/squads/phparchitect"},{"@type":"ListItem","position":3,"name":"Using jscpd and Mago to fix AI generated code duplication in PHP"}]}
```

