<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Jonas Elfering</title>
    <description>The latest articles on DEV Community by Jonas Elfering (@keulinho).</description>
    <link>https://dev.to/keulinho</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F11449%2Fcba1e641-2fb1-427b-99b1-0b1c8b50207f.jpg</url>
      <title>DEV Community: Jonas Elfering</title>
      <link>https://dev.to/keulinho</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/keulinho"/>
    <language>en</language>
    <item>
      <title>Preparing for Shopware 6.8: early guidance for developers</title>
      <dc:creator>Jonas Elfering</dc:creator>
      <pubDate>Thu, 29 Oct 2026 10:01:00 +0000</pubDate>
      <link>https://dev.to/shopware/preparing-for-shopware-68-early-guidance-for-developers-2c7m</link>
      <guid>https://dev.to/shopware/preparing-for-shopware-68-early-guidance-for-developers-2c7m</guid>
      <description>&lt;p&gt;At our October Hacktoberfest in Schöppingen, we came together with the community to share what we’ve been working on and explore what comes next.&lt;br&gt;
Preparing for Shopware 6.8 was part of that conversation: I walked through the latest developments, with a practical focus on what you can start doing today.&lt;br&gt;
From testing upcoming changes behind feature flags to checking compatibility and sharing feedback, there are steps that can make the next upgrade easier.&lt;br&gt;
In this blog post, we’ll walk through those learnings and show how to make preparation part of regular development work, rather than leaving it until release day.&lt;/p&gt;

&lt;p&gt;Our goal is to make 6.8 the smoothest, most predictable and easiest-to-upgrade Shopware 6 major release so far.&lt;br&gt;
Compatibility tooling, testable feature flags and community feedback give agencies and plugin developers more time to understand the changes and prepare their projects.&lt;/p&gt;

&lt;p&gt;You can already join the conversation in Discord &lt;strong&gt;&lt;a href="https://discord.com/channels/1308047705309708348/1557367351471644732" rel="noopener noreferrer"&gt;#feedback-6_8&lt;/a&gt;&lt;/strong&gt;.&lt;br&gt;
Trying the available tools and sharing difficult cases now gives our team valuable input while the implementation and upgrade approach can still evolve.&lt;/p&gt;

&lt;p&gt;Shopware 6.8 is planned for 2027, with timing and scope subject to change as planning is still at an early stage.&lt;br&gt;
That gives you a useful preparation window: start identifying the work now and include it in next year’s plans.&lt;/p&gt;

&lt;h2&gt;
  
  
  Start with a clear picture of the project
&lt;/h2&gt;

&lt;p&gt;The first step is to map each installation: its Shopware version, hosting requirements, plugins, custom code and integrations.&lt;br&gt;
That picture helps identify which changes could affect customer journeys or business processes, and provides the basis for a sequence of tasks and an initial estimate.&lt;/p&gt;

&lt;p&gt;The budget needs to cover both preparation and the major upgrade itself.&lt;br&gt;
Compatibility work, testing and coordination with plugin vendors take time even when the final version change becomes smaller.&lt;br&gt;
Making that work visible early helps merchants plan costs and schedule changes around their business.&lt;/p&gt;

&lt;p&gt;Tooling can help reveal dependencies and missing work.&lt;br&gt;
The project plan still needs someone who understands how the shop operates.&lt;/p&gt;

&lt;p&gt;Use that to decide where to start:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check the customer journeys and integrations that could behave differently.&lt;/li&gt;
&lt;li&gt;Use the major-version flag and compatibility checks to find affected code.&lt;/li&gt;
&lt;li&gt;Identify preparation work you can release separately, before the major upgrade.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Test the behavior customers depend on
&lt;/h2&gt;

&lt;p&gt;Code can continue to run while an integration behaves differently.&lt;br&gt;
Some problems only become visible later, when a customer uses a particular discount or an order reaches another system.&lt;br&gt;
Feature flags offer an early way to explore these changes in a test environment, alongside automated tests and checks of real customer journeys.&lt;br&gt;
The following examples show where changed behavior could affect a shop and what teams can check in advance.&lt;/p&gt;

&lt;p&gt;For these checks, a successful request is only the starting point.&lt;br&gt;
A small change in the tax calculator is a good example: the code can still run, while the amounts your payment integration receives have changed.&lt;br&gt;
Build assertions around the result the customer or connected system depends on, rather than only checking that checkout returns successfully.&lt;/p&gt;

&lt;h3&gt;
  
  
  Caching and personalized content
&lt;/h3&gt;

&lt;p&gt;The cache rework keeps HTTP caching active for cacheable pages even when customers are logged in or have items in their carts, allowing more efficient responses.&lt;br&gt;
With &lt;code&gt;CACHE_REWORK&lt;/code&gt; enabled in a test environment, compare personalized content across different customers and cart states.&lt;br&gt;
Check cache invalidation separately.&lt;br&gt;
Customizations that assume these responses are never cached could accidentally place customer-specific information in a shared response.&lt;br&gt;
Testing those assumptions protects both privacy and correctness.&lt;/p&gt;

&lt;h3&gt;
  
  
  Taxes and discounts
&lt;/h3&gt;

&lt;p&gt;We’re correcting rounding edge cases where the cart calculation could produce slightly incorrect amounts.&lt;br&gt;
The proportional cart tax changes reuse existing item taxes for percentage discounts, surcharges and split quantities.&lt;br&gt;
Even a one-cent correction can matter when orders are passed to payment, ERP or accounting systems, so we’re introducing the change behind a feature flag before making it part of the major upgrade.&lt;/p&gt;

&lt;p&gt;Use the same cart before and after enabling the flag, with a percentage discount and products at different tax rates.&lt;br&gt;
Compare the line-item taxes and final totals, then follow those values into the payment request and your downstream integrations.&lt;br&gt;
Include split quantities if your shop uses them.&lt;br&gt;
A difference of a cent is exactly the sort of result that can slip past a test which only checks whether an order was created.&lt;/p&gt;

&lt;h3&gt;
  
  
  Document generation
&lt;/h3&gt;

&lt;p&gt;The experimental &lt;code&gt;DOCUMENT_GENERATION_REWORK&lt;/code&gt; separates document data preparation from rendering, making different document types and output formats easier to extend.&lt;br&gt;
Existing Twig templates remain, while PHP integrations need review against the new extension points.&lt;br&gt;
Test custom data and generated output.&lt;br&gt;
The planned transition retains the old implementation as a fallback in 6.8, with removal planned for 6.9.&lt;/p&gt;

&lt;p&gt;Adding more formats has made the old system harder to extend, so testing only the PDF would leave part of that change unchecked.&lt;br&gt;
For example, take an invoice with custom data added by your plugin and generate it in every format you support, such as PDF and accessible HTML.&lt;br&gt;
Check that the data reaches each output and that your Twig customizations still render as intended.&lt;/p&gt;

&lt;h3&gt;
  
  
  Flow execution
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;FLOW_EXECUTION_AFTER_BUSINESS_PROCESS&lt;/code&gt; is already available for testing and is planned to become the default in 6.8.&lt;br&gt;
For HTTP requests, it allows the customer response to be sent before flow actions finish, reducing the impact of expensive or failing flows on checkout completion.&lt;br&gt;
Execution remains in the same process.&lt;br&gt;
Review assumptions about tags, state changes and other flow results being available immediately; transaction-critical work belongs in synchronous subscribers.&lt;/p&gt;

&lt;p&gt;Consider a flow that adds a tag to an order or customer.&lt;br&gt;
If your checkout response reads that tag to decide what to display, it can no longer assume the tag is already there.&lt;br&gt;
Test the response itself as well as the eventual database state: the flow may complete correctly while the page has already been rendered without its result.&lt;/p&gt;

&lt;h2&gt;
  
  
  Explore the growing compatibility toolkit
&lt;/h2&gt;

&lt;p&gt;The major-version flag, &lt;code&gt;V6_8_0_0=1&lt;/code&gt;, can expose upcoming incompatibilities where the corresponding checks are implemented.&lt;br&gt;
A flagged CI run alongside the normal run helps reveal what needs attention while retaining coverage of current behavior.&lt;br&gt;
Coverage is expanding, so interpret the results alongside behavioral tests and the official 6.8 upgrade guidance, which is still a work in progress.&lt;/p&gt;

&lt;p&gt;We’re also making compatibility information more precise.&lt;br&gt;
Released PHP attributes describe planned API changes more clearly, while the accompanying future-compatibility PHPStan rules remain experimental and opt-in.&lt;br&gt;
An open polyfill proposal explores easier support for several Shopware versions in one plugin release.&lt;/p&gt;

&lt;p&gt;Administration extensions already have experimental ESLint and type-checking support.&lt;br&gt;
Runtime guards are still being developed.&lt;br&gt;
Storefront template guards and warning prototypes are also progressing, with questions around multi-version support still being worked through.&lt;/p&gt;

&lt;p&gt;The Administration code already provides examples of this approach.&lt;br&gt;
Its ESLint rules can flag a deprecated &lt;code&gt;sw-button&lt;/code&gt; and point you to &lt;code&gt;mt-button&lt;/code&gt;.&lt;br&gt;
Use the rules shipped with your installed Shopware version; this illustrates what the tooling can do today.&lt;/p&gt;

&lt;p&gt;The existing Shopware CLI project upgrade workflow already supports local upgrade preparation.&lt;br&gt;
The aim is to bring the 6.8 compatibility checks together in a unified diagnostic experience through Shopware CLI, making preparation easier for developers.&lt;br&gt;
As these building blocks develop through the rest of 2026, concrete feedback can help us improve them.&lt;/p&gt;

&lt;p&gt;Run PHPUnit, PHPStan and the available Administration checks as separate CI steps until the unified command is released.&lt;/p&gt;

&lt;h2&gt;
  
  
  Build compatibility into regular maintenance
&lt;/h2&gt;

&lt;p&gt;For plugin developers, a reliable CI pipeline is the foundation.&lt;br&gt;
Each new Shopware release provides an opportunity to run the checks, investigate failures and review fixes.&lt;br&gt;
Testing across the supported version range then provides the basis for releasing a compatible update.&lt;/p&gt;

&lt;p&gt;AI agents can help analyze failures and propose changes.&lt;br&gt;
Developers still need to review, test and approve them.&lt;br&gt;
Smaller batches, perhaps alongside each monthly release, are easier to inspect than a single large set of changes shortly before the major upgrade.&lt;br&gt;
Agency teams can use the same rhythm for custom project code.&lt;/p&gt;

&lt;p&gt;My recommendation is to get CI in place before handing changes to an agent.&lt;br&gt;
A small, tested fix each month is much easier to review than a pull request that rewrites the plugin just before 6.8.&lt;/p&gt;

&lt;h2&gt;
  
  
  Separate the preparation steps
&lt;/h2&gt;

&lt;p&gt;You don’t need to wait for a Shopware 6.8 upgrade project to start preparing.&lt;br&gt;
Where your current Shopware version, extensions and hosting support it, upgrade PHP and the database in advance, then release compatible plugin updates and custom-code changes separately.&lt;br&gt;
Test each change before moving to the next one.&lt;br&gt;
That keeps the major upgrade smaller and makes problems easier to trace.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prepare PHP.&lt;/strong&gt;&lt;br&gt;
PHP 8.5 is the planned minimum for 6.8.&lt;br&gt;
Move only when the currently installed Shopware version, extensions and dependencies support it.&lt;br&gt;
Resolve Symfony deprecations on compatible current releases ahead of the planned move to Symfony 8.x or later.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Prepare the database.&lt;/strong&gt;&lt;br&gt;
The planned minimums are MySQL 8.4 or MariaDB 11.4, depending on the engine you use.&lt;br&gt;
Confirm current-release and hosting support, and test custom migrations before upgrading separately.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Update plugins.&lt;/strong&gt;&lt;br&gt;
Prefer releases supporting both the current and target Shopware versions where available.&lt;br&gt;
Check vendor plans and identify gaps early.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Adapt custom code.&lt;/strong&gt;&lt;br&gt;
Address deprecations and review affected integrations, themes and components.&lt;br&gt;
Planned Twig 4 and Symfony UX Twig Component 3 changes also deserve attention, especially for custom extensions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Validate changed behavior.&lt;/strong&gt;&lt;br&gt;
Test relevant flags individually, keep the major-flag CI run, and verify customer journeys and integrations in staging.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Complete the major upgrade.&lt;/strong&gt;&lt;br&gt;
Bring the prepared components together and validate the full shop.&lt;br&gt;
Separating earlier changes makes unexpected results easier to trace.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Share the cases that need more support
&lt;/h2&gt;

&lt;p&gt;Early testing can improve both your own plan and the tools available to everyone.&lt;br&gt;
Share a reproducible example, the Shopware versions you need to support, and what makes a migration difficult in Discord &lt;strong&gt;&lt;a href="https://discord.com/channels/1308047705309708348/1557367351471644732" rel="noopener noreferrer"&gt;#feedback-6_8&lt;/a&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The greatest opportunity to influence the approach is before scope settles and the first release candidate arrives.&lt;br&gt;
Start with one project, try the available checks and bring the findings back to the team.&lt;br&gt;
Those small steps can turn preparation into steady progress and reduce surprises when it is time to upgrade.&lt;/p&gt;

&lt;p&gt;A useful report might show a plugin that needs two different class declarations to support old and new interfaces, or a template warning that flags an intentional compatibility fallback.&lt;br&gt;
Include a small code example, the failing check and the versions you need to keep working.&lt;br&gt;
These are the kinds of cases I’d like you to share: they show us where to focus our efforts to make Shopware 6.8 the smoothest upgrade to date.&lt;/p&gt;

</description>
      <category>shopware</category>
      <category>php</category>
    </item>
    <item>
      <title>A new security reality for commerce</title>
      <dc:creator>Jonas Elfering</dc:creator>
      <pubDate>Tue, 27 Oct 2026 10:07:08 +0000</pubDate>
      <link>https://dev.to/shopware/a-new-security-reality-for-commerce-8k1</link>
      <guid>https://dev.to/shopware/a-new-security-reality-for-commerce-8k1</guid>
      <description>&lt;p&gt;&lt;em&gt;As threats evolve, speed matters more—and everyone in the Shopware ecosystem has a part to play.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;The security landscape is changing: AI-assisted research is helping researchers and attackers find weaknesses and develop working exploits faster. We are expanding our security work, hardening Shopware, and improving how security fixes reach shops. Keeping shops protected is a shared effort: our work has the greatest impact when merchants make security an operational priority, agencies deploy updates promptly, and extension partners keep their code secure and dependencies up to date.&lt;/p&gt;

&lt;h2&gt;
  
  
  What we are doing at Shopware
&lt;/h2&gt;

&lt;p&gt;Publishing security patches remains an essential part of our work. But addressing individual vulnerabilities is only one part of adapting to this situation.&lt;/p&gt;

&lt;h3&gt;
  
  
  Expanding the security team
&lt;/h3&gt;

&lt;p&gt;We are expanding our security team to strengthen both proactive security work and our response to findings.&lt;/p&gt;

&lt;p&gt;This includes reviewing designs and code, improving automated checks, and helping development teams address recurring root causes.&lt;/p&gt;

&lt;p&gt;We also want to improve report triage and fix coordination, turning lessons from findings into practical guidance and safer development patterns across Shopware.&lt;/p&gt;

&lt;p&gt;If you want to help improve the security of Shopware and its ecosystem, have a look at our &lt;a href="https://careers.shopware.com" rel="noopener noreferrer"&gt;open positions&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Looking for vulnerabilities proactively
&lt;/h3&gt;

&lt;p&gt;We continue to combine regular, externally conducted penetration testing with our existing &lt;a href="https://www.shopware.com/en/contact/security-reporting/" rel="noopener noreferrer"&gt;bug-bounty program&lt;/a&gt;, through which researchers can responsibly report vulnerabilities. Additionally, we are actively scanning for vulnerabilities using the most capable AI models available to us.&lt;/p&gt;

&lt;p&gt;These approaches complement each other. External researchers bring different perspectives, while AI-assisted analysis helps us examine more code and possible interactions. A model's output still needs to be validated: a plausible description is not proof that a vulnerability exists, and a scan that finds nothing is not proof that the code is secure.&lt;/p&gt;

&lt;p&gt;Therefore, we treat AI as an additional tool for finding problems, not as a replacement for security engineering or the researchers who work with us.&lt;/p&gt;

&lt;p&gt;We already use the latest advances in AI to scan incoming code. At the same time, we need to find and fix weaknesses in existing code, prioritizing findings according to their potential impact and the risk they pose to shops.&lt;/p&gt;

&lt;p&gt;The likely outcome is more security fixes and more frequent security releases. That is a positive consequence of finding and addressing weaknesses that might previously have remained undetected. Agencies, merchants, and extension partners should be prepared for this increased update cadence and have a process in place to apply security fixes promptly.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making exploit chains harder to complete
&lt;/h3&gt;

&lt;p&gt;Fixing the initial vulnerability is important, but we also need to look at what an attacker could do after gaining an initial foothold.&lt;/p&gt;

&lt;p&gt;For example, an attacker who gains limited access should not automatically be able to turn that access into broader control over the shop. That depends on the boundaries between different parts of the system and on which operations remain possible with the access they have gained.&lt;/p&gt;

&lt;p&gt;We will further harden these boundaries to block common exploit chains and limit the impact of an initial compromise. This does not make the original vulnerability acceptable or remove the need to patch it. It adds protection for cases where one defense has already failed.&lt;/p&gt;

&lt;p&gt;We are also improving the forensic data available to help detect and investigate attacks. The goal is to make it easier to identify exploitation attempts while they are happening and, if an incident occurs, reconstruct what happened and understand which parts of the shop were affected.&lt;/p&gt;

&lt;h3&gt;
  
  
  Making security fixes easier to apply
&lt;/h3&gt;

&lt;p&gt;Publishing a security fix gives merchants a way to protect their shops, but it also gives attackers clues about the vulnerability. Getting that protection into production quickly is therefore just as important as making it available. Once a vulnerability is disclosed, exploitation attempts can follow quickly and may be automated. Shops affected by that vulnerability need a process that gets protection into production promptly.&lt;/p&gt;

&lt;p&gt;We are rethinking how we deliver security patches so that securing a shop requires less time and coordination. Agencies and merchants need to be able to apply protection quickly without turning every security update into a larger upgrade project.&lt;/p&gt;

&lt;p&gt;We are strengthening the testing, compatibility, and reliability of security updates, building on what we have learned from previous releases. The goal is to help merchants and agencies apply protection quickly and with confidence.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the security landscape is changing
&lt;/h2&gt;

&lt;p&gt;Security updates have always been part of running an online shop. However, the number of security reports we receive and the pace at which attackers act on disclosed vulnerabilities have changed considerably. That has consequences for how we develop Shopware, but also for how extensions are maintained and production shops are operated.&lt;/p&gt;

&lt;p&gt;Our own reporting data helps explain why we are strengthening these efforts. The following chart shows Shopware 6 bug-bounty reports and security advisory records created over time.&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxh7ldgwcq4mfgerol1bi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fxh7ldgwcq4mfgerol1bi.png" alt=" " width="800" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;These figures include unpublished advisory records and do not represent distinct confirmed vulnerabilities; reports and advisories do not map one to one.&lt;/p&gt;

&lt;p&gt;The increase in findings does not tell us how many shops are affected or compromised. More reports do not, by themselves, show that the software has become less secure. They show that more potential weaknesses are being reported and investigated. AI-assisted research can uncover vulnerabilities that likely remained undetected before these tools became available.&lt;/p&gt;

&lt;p&gt;However, those tools are available to attackers as well. If a security researcher can find an issue with AI, we have to assume that a bad actor may independently find it too. Responsible disclosure therefore cannot be treated as a period in which only the researcher and the vendor know about a vulnerability. The time available to investigate, fix, and deploy protection may be much shorter, even before an advisory is published.&lt;/p&gt;

&lt;p&gt;Once an advisory is public, we already see automated exploitation attempts within days. So both parts matter: acting quickly on incoming reports and getting the resulting protection into production promptly.&lt;/p&gt;

&lt;h2&gt;
  
  
  This is an industry-wide challenge
&lt;/h2&gt;

&lt;p&gt;AI-assisted research is changing both how many weaknesses are found and how readily they can be turned into working attacks.&lt;/p&gt;

&lt;p&gt;The recent &lt;a href="https://thephp.foundation/blog/2026/10/21/todays-php-security-release-and-how-were-strengthening-php-security/" rel="noopener noreferrer"&gt;PHP security release&lt;/a&gt; illustrates this: &lt;a href="https://calif.io/php2shell/" rel="noopener noreferrer"&gt;PHP2Shell researchers&lt;/a&gt; used AI to help demonstrate exploitation of a long-standing weakness whose impact had remained unproven.&lt;/p&gt;

&lt;p&gt;Software does not have to change for its practical exposure to change—the tools available to researchers and attackers can change around it.&lt;/p&gt;

&lt;p&gt;Other projects are seeing a similar increase in security findings. In a &lt;a href="https://www.linkedin.com/feed/update/urn:li:activity:7517910546206179328/" rel="noopener noreferrer"&gt;recent post about Symfony and Twig&lt;/a&gt;, Fabien Potencier described a sharp rise in reports and advisories alongside the growing use of AI in security research.&lt;/p&gt;

&lt;p&gt;These are just a few examples of what has happened across the wider ecosystem in the last month alone:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Magento and Adobe Commerce:&lt;/strong&gt; &lt;a href="https://sansec.io/research/blockstrap-magento-rce" rel="noopener noreferrer"&gt;Sansec reproduced four BlockStrap exploit routes within 24 hours of Adobe’s patch&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;WordPress:&lt;/strong&gt; &lt;a href="https://patchstack.com/articles/cve-2026-87902-attackers-started-probing-wordpress-sites-hours-after-the-patch/" rel="noopener noreferrer"&gt;Patchstack observed probing within hours of a security patch, followed by exploitation attempts the next day&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shopify's app ecosystem:&lt;/strong&gt; &lt;a href="https://www.logbase.io/selleasy/updates/incident-20261013" rel="noopener noreferrer"&gt;Selleasy reported an incident involving injected scripts that redirected customers to phishing pages&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These examples illustrate a shared challenge across platforms and their ecosystems, not a comparison of vendors' security records.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this means for extension partners
&lt;/h2&gt;

&lt;p&gt;A shop consists of more than Shopware core. Extensions can handle customer data, expose API routes, process files, or change what happens during checkout. Their security is therefore part of the security of the shop itself.&lt;/p&gt;

&lt;p&gt;In successful attacks we have investigated, third-party extensions have already been used as part of the attack. This is not just a theoretical concern that might become relevant at some point in the future.&lt;/p&gt;

&lt;p&gt;If you maintain extensions, start reviewing them now. A useful starting point is to look at where data enters your extension and what a caller is allowed to do with it:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Are permissions and ownership checked on the server, rather than only in the Administration interface?&lt;/li&gt;
&lt;li&gt;Is untrusted input handled safely before it reaches database queries, templates, or file operations?&lt;/li&gt;
&lt;li&gt;Are the libraries your extension depends on current and free of known vulnerabilities?&lt;/li&gt;
&lt;li&gt;Could limited access to one feature be combined with another feature to gain more access than intended?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;AI-assisted reviews can help with this work, but the findings still need to be checked against the actual behavior of the extension.&lt;/p&gt;

&lt;p&gt;We are also exploring how additional tools and processes could help extension partners identify vulnerabilities, coordinate findings, and deliver security fixes more easily. In parallel, partners should start reviewing their code and addressing the issues they find.&lt;/p&gt;

&lt;h2&gt;
  
  
  What agencies and merchants should do
&lt;/h2&gt;

&lt;p&gt;For practical guidance on supported versions, infrastructure security, and extension management, see our &lt;a href="https://developer.shopware.com/docs/guides/hosting/installation-updates/security-best-practices/" rel="noopener noreferrer"&gt;Security Best Practices guide&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Know which responsibilities your hosting model covers
&lt;/h3&gt;

&lt;p&gt;With &lt;a href="https://docs.shopware.com/en/shopware-6-en/in-the-cloud" rel="noopener noreferrer"&gt;Shopware SaaS&lt;/a&gt;, we take care of securing and maintaining the platform and its infrastructure, including automatically applying platform updates and security patches.&lt;/p&gt;

&lt;p&gt;You do not need to manage servers or install the Security Plugin yourself.&lt;/p&gt;

&lt;p&gt;With &lt;a href="https://developer.shopware.com/docs/products/paas/shopware/" rel="noopener noreferrer"&gt;Shopware PaaS Native&lt;/a&gt;, we manage the underlying infrastructure, including servers, networking, managed databases, and platform backups, and provide a web application firewall enabled by default.&lt;/p&gt;

&lt;p&gt;You or your agency still manage the application: testing and deploying Shopware, Security Plugin, extension, and dependency updates, and securing your custom code.&lt;/p&gt;

&lt;p&gt;You also select a supported, compatible PHP version in the application configuration.&lt;/p&gt;

&lt;p&gt;Runtime extension management is already disabled; extensions are managed through Composer and deployments.&lt;/p&gt;

&lt;p&gt;Managed infrastructure and a firewall do not replace prompt application updates.&lt;/p&gt;

&lt;p&gt;In both models, merchants remain responsible for their configuration, access and user management, and the security of external apps and integrations they operate or connect.&lt;/p&gt;

&lt;p&gt;For self-hosted shops, infrastructure security also needs to be managed by you or your hosting provider.&lt;/p&gt;

&lt;h3&gt;
  
  
  Keep the Security Plugin installed and up to date
&lt;/h3&gt;

&lt;p&gt;We are changing our recommendation for self-hosted shops.&lt;/p&gt;

&lt;p&gt;Previously, we recommended the &lt;a href="https://store.shopware.com/en/swag136939272659f/shopware-6-security-plugin.html" rel="noopener noreferrer"&gt;Shopware Security Plugin&lt;/a&gt; primarily when a platform update could not be deployed immediately.&lt;/p&gt;

&lt;p&gt;We now recommend keeping it installed, activated, and up to date with a version compatible with the shop, even when the platform itself is already fully up to date. See our &lt;a href="https://developer.shopware.com/docs/guides/hosting/installation-updates/security-best-practices/security-plugin.html" rel="noopener noreferrer"&gt;Security Plugin guide&lt;/a&gt; for the updated recommendation, compatibility, and installation instructions.&lt;/p&gt;

&lt;p&gt;Having the plugin in place makes it easier to apply the next security update promptly.&lt;/p&gt;

&lt;p&gt;Make sure your shop runs a Shopware version that is still receiving security support, as shown in our &lt;a href="https://developer.shopware.com/release-notes/" rel="noopener noreferrer"&gt;release policy&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The plugin changelog lists the issues fixed by each plugin release.&lt;/p&gt;

&lt;p&gt;The Security Plugin provides a fast way to apply supported fixes to known vulnerabilities in Shopware’s own code, especially when a complete platform update cannot be deployed immediately. It does not replace updates to PHP, third-party dependencies, extensions, or Shopware itself. Additional hardening and broader security improvements are delivered in regular Shopware releases and are usually not backported through the plugin. Keeping Shopware and its extensions up to date therefore remains essential to benefit from those additional layers of protection.&lt;/p&gt;

&lt;p&gt;When a relevant Security Plugin release becomes available, update it as soon as possible. Do not defer that work to the next weekly or monthly maintenance window. We see automated exploitation attempts within days of advisory publication, so a process that routinely leaves shops unprotected for weeks does not match the threat.&lt;/p&gt;

&lt;p&gt;That does not mean skipping validation. It means having a process in place that allows an urgent security update to be checked and deployed promptly, separately from larger feature releases or routine maintenance.&lt;/p&gt;

&lt;p&gt;If you suspect your shop has already been compromised, applying a security update alone does not establish that it is clean; contact your hosting provider and agency first, and follow our &lt;a href="https://developer.shopware.com/docs/guides/hosting/installation-updates/security-best-practices/incident-response.html" rel="noopener noreferrer"&gt;guide to responding to a cyberattack&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Treat security communication as an operational task
&lt;/h3&gt;

&lt;p&gt;When we send a security notice, it needs to reach someone who can act on it. Receiving an email is not the same as protecting the shop.&lt;/p&gt;

&lt;p&gt;Agencies and merchants should agree on who receives those notices, who checks whether a shop is affected, and who is responsible for deploying the required protection. The handover between merchant, agency, and hosting provider should already be clear before an urgent update arrives.&lt;/p&gt;

&lt;p&gt;We also have a responsibility to make our communication clear and actionable. Security notices should explain what is affected, what action is required, and how urgently it needs to happen. Please treat that communication seriously and follow the instructions for the specific issue.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: Adapt the processes around the software too
&lt;/h2&gt;

&lt;p&gt;Shopware is adapting how we find vulnerabilities, harden the platform, and deliver protection.&lt;/p&gt;

&lt;p&gt;Here are the steps the ecosystem can take now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Check that your Shopware version is still receiving security support using our &lt;a href="https://developer.shopware.com/release-notes/" rel="noopener noreferrer"&gt;release policy&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Keep a compatible Security Plugin installed, activated, and up to date.&lt;/li&gt;
&lt;li&gt;Agree who receives security notices, assesses whether your shop is affected, and deploys urgent updates.&lt;/li&gt;
&lt;li&gt;If you maintain extensions, review your code for security weaknesses and deliver fixes promptly.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>security</category>
      <category>shopware</category>
    </item>
    <item>
      <title>When `@deprecated` cries wolf: Making Shopware’s next major upgrades easier</title>
      <dc:creator>Jonas Elfering</dc:creator>
      <pubDate>Tue, 25 Aug 2026 06:48:24 +0000</pubDate>
      <link>https://dev.to/shopware/when-deprecated-cries-wolf-making-shopwares-next-major-upgrades-easier-983</link>
      <guid>https://dev.to/shopware/when-deprecated-cries-wolf-making-shopwares-next-major-upgrades-easier-983</guid>
      <description>&lt;p&gt;When PHPStan reports that your extension calls a deprecated method, the expected next step is quite clear: find the replacement and migrate your code.&lt;/p&gt;

&lt;p&gt;But what if there is no replacement?&lt;/p&gt;

&lt;p&gt;Consider &lt;code&gt;Context::scope()&lt;/code&gt;. Previously, its planned change for Shopware 6.8 was announced like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cd"&gt;/**
 * @deprecated tag:v6.8.0 - reason:new-optional-parameter - parameter $states will be added
 */&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$scope&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;\Closure&lt;/span&gt; &lt;span class="nv"&gt;$callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;mixed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Static analysis sees &lt;code&gt;@deprecated&lt;/code&gt; and reports every call to the method. However, the method is not going away. A new &lt;em&gt;optional&lt;/em&gt; parameter will be added, so existing calls will continue to work without any changes.&lt;/p&gt;

&lt;p&gt;There is no alternative API to migrate to and no warning to resolve. In this situation, &lt;code&gt;@deprecated&lt;/code&gt; is effectively crying wolf.&lt;/p&gt;

&lt;p&gt;With Shopware 6.7.14.0, we are changing how these planned API changes are communicated. Real deprecations remain deprecations. Other backward-compatibility changes are now described with dedicated, structured PHP attributes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The immediate result is less noise for extension developers.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Additionally, the new attributes give us a foundation for preparing extensions for Shopware 6.8 - and future major releases - before those releases arrive.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Shopware now uses two different signals for two different purposes:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;@deprecated&lt;/code&gt; means that an API is obsolete and will be removed or replaced. Extension developers need to migrate away from it.&lt;/li&gt;
&lt;li&gt;BC-change attributes describe a future change to an API that remains available, such as a new parameter, a narrower return type, or a class becoming final.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The attributes also distinguish between changes that affect code &lt;em&gt;calling&lt;/em&gt; an API and changes that affect classes &lt;em&gt;extending&lt;/em&gt; it.&lt;/p&gt;

&lt;p&gt;This means deprecation warnings become trustworthy and actionable again, while planned contract changes carry enough structured information for PHPStan, Rector, IDEs, and other tools to reason about them.&lt;/p&gt;

&lt;h2&gt;
  
  
  We were asking &lt;code&gt;@deprecated&lt;/code&gt; to do two different jobs
&lt;/h2&gt;

&lt;p&gt;The commonly understood meaning of &lt;code&gt;@deprecated&lt;/code&gt; in the PHP ecosystem is quite narrow: this API should no longer be used. IDEs may strike it through, and static-analysis tools warn when application code still depends on it.&lt;/p&gt;

&lt;p&gt;This is useful behaviour. If a method is going away, extension developers should know about it as early as possible.&lt;/p&gt;

&lt;p&gt;Shopware, however, also used &lt;code&gt;@deprecated&lt;/code&gt; as an internal planning mechanism for the next major version. A &lt;code&gt;reason:*&lt;/code&gt; marker could announce that:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A return type will become narrower.&lt;/li&gt;
&lt;li&gt;A parameter type will change.&lt;/li&gt;
&lt;li&gt;A new optional parameter will be added.&lt;/li&gt;
&lt;li&gt;A class will become final or internal.&lt;/li&gt;
&lt;li&gt;A method’s visibility will change.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are all relevant backward-compatibility changes, but they are not all deprecations.&lt;/p&gt;

&lt;p&gt;In many cases, the annotated method remains the correct API to use. Whether an extension needs to change anything depends on &lt;em&gt;how&lt;/em&gt; it uses that API. Calling a method and overriding it in a subclass are two very different forms of dependency.&lt;/p&gt;

&lt;p&gt;The standard &lt;code&gt;@deprecated&lt;/code&gt; signal cannot express that distinction. It also cannot express a future type, parameter name, default value, or affected audience in a machine-readable form. Static-analysis tools should not be expected to understand Shopware-specific prose inside a PHPDoc annotation.&lt;/p&gt;

&lt;p&gt;We could have recommended that every extension add more ignore patterns. But a blanket ignore would also hide genuine deprecations (the warnings where an extension developer really does need to act).&lt;/p&gt;

&lt;p&gt;The problem was therefore not PHPStan being too strict. We were giving it the wrong signal.&lt;/p&gt;

&lt;h2&gt;
  
  
  A more precise model for backward-compatibility changes
&lt;/h2&gt;

&lt;p&gt;The new attributes live in the &lt;code&gt;Shopware\Core\Framework\Deprecation\BCChange&lt;/code&gt; namespace. There are currently 15 concrete attributes covering changes to types, parameters, visibility, inheritance, and exception contracts.&lt;/p&gt;

&lt;p&gt;Every attribute belongs to one or both of two audiences:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;CallSiteCompatibilityChange&lt;/code&gt; describes a change that may affect code calling a method.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;ExtenderCompatibilityChange&lt;/code&gt; describes a change that may affect a subclass or method override.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, narrowing a parameter type affects callers that currently pass a value outside the future type. Widening that parameter type does not affect callers, but it may make an overriding method incompatible.&lt;/p&gt;

&lt;p&gt;Return types work in the opposite direction because PHP return types are covariant. A narrower return type does not break callers, but subclasses overriding the method may need to adjust their declaration.&lt;/p&gt;

&lt;p&gt;That is also why the attributes have directional names such as &lt;code&gt;ReturnTypeNarrowing&lt;/code&gt;, &lt;code&gt;ReturnTypeWidening&lt;/code&gt;, &lt;code&gt;ParameterTypeNarrowing&lt;/code&gt;, and &lt;code&gt;ParameterTypeWidening&lt;/code&gt;. The direction tells us who may be affected.&lt;/p&gt;

&lt;p&gt;Some changes affect both sides. If a method becomes internal, for example, code calling it and code extending it may both need to stop relying on it.&lt;/p&gt;

&lt;p&gt;Whether you need to act is therefore no longer answered with a generic “this method is deprecated.” It is answered by the concrete change and the way your extension uses the API.&lt;/p&gt;

&lt;p&gt;The design started as a &lt;a href="https://github.com/shopware/shopware/discussions/17798" rel="noopener noreferrer"&gt;community-driven RFC&lt;/a&gt; and was refined through discussion and implementation feedback. It was introduced through the &lt;a href="https://github.com/shopware/shopware/pull/17979" rel="noopener noreferrer"&gt;attribute family&lt;/a&gt;, &lt;a href="https://github.com/shopware/shopware/pull/17985" rel="noopener noreferrer"&gt;PHPStan enforcement&lt;/a&gt;, and the &lt;a href="https://github.com/shopware/shopware/pull/17992" rel="noopener noreferrer"&gt;migration of existing planning annotations&lt;/a&gt;; &lt;code&gt;ParameterDefaultValueChange&lt;/code&gt; followed as a &lt;a href="https://github.com/shopware/shopware/pull/18699" rel="noopener noreferrer"&gt;later refinement&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  How extension developers can use the new information
&lt;/h2&gt;

&lt;p&gt;The attributes themselves are marked &lt;code&gt;@internal&lt;/code&gt;. They are not intended as a new extension API that plugins should instantiate or add to their own code.&lt;/p&gt;

&lt;p&gt;What extension developers can rely on is the meaning of the announcement on a Shopware Core API: what changes, when it changes, and whether callers or extenders may be affected.&lt;/p&gt;

&lt;p&gt;Let us return to &lt;code&gt;Context::scope()&lt;/code&gt;. Its planned change is now expressed as structured metadata:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;NewOptionalParameter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'v6.8.0'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;parameterName&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'states'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;parameterType&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'array'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;defaultValue&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$scope&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nc"&gt;\Closure&lt;/span&gt; &lt;span class="nv"&gt;$callback&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;mixed&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;For callers, there is nothing to do. The new parameter is optional, so existing calls remain valid.&lt;/p&gt;

&lt;p&gt;For a class overriding the method, the situation is different. The override can add the optional parameter today:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;scope&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$scope&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="nc"&gt;\Closure&lt;/span&gt; &lt;span class="nv"&gt;$callback&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="k"&gt;array&lt;/span&gt; &lt;span class="nv"&gt;$states&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[],&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="n"&gt;mixed&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Additional optional parameters are compatible with the current parent declaration. Once Shopware 6.8 adds the parameter, the override remains compatible. The extension can therefore prepare without a Shopware version check or two separate implementations.&lt;/p&gt;

&lt;p&gt;Return-type narrowing provides another example. &lt;code&gt;Field::setFlags()&lt;/code&gt; currently returns &lt;code&gt;self&lt;/code&gt;, but will return &lt;code&gt;static&lt;/code&gt; in Shopware 6.8:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="na"&gt;#[ReturnTypeNarrowing(version: 'v6.8.0', newType: 'static')]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;setFlags&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Flag&lt;/span&gt; &lt;span class="mf"&gt;...&lt;/span&gt;&lt;span class="nv"&gt;$flags&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;self&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Callers are not affected because every &lt;code&gt;static&lt;/code&gt; value is also a valid &lt;code&gt;self&lt;/code&gt; value. An overriding method can already declare &lt;code&gt;static&lt;/code&gt;, though, because PHP permits covariant return types:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;setFlags&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;Flag&lt;/span&gt; &lt;span class="mf"&gt;...&lt;/span&gt;&lt;span class="nv"&gt;$flags&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;static&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// ...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, one declaration works with both the current version and the future one.&lt;/p&gt;

&lt;p&gt;Parameter renames mainly affect named arguments. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="err"&gt;#&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;ParameterNameChange&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;version&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'v6.8.0'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;parameterName&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'filename'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;newName&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="s1"&gt;'fileName'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$filename&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A call using &lt;code&gt;filename:&lt;/code&gt; will break after the rename. Switching to positional arguments works with both parameter names:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DomainVerificationRequestStruct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$fileName&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;a href="https://developer.shopware.com/docs/resources/guidelines/code/backward-compatibility.html#announced-api-changes-bc-change-attributes" rel="noopener noreferrer"&gt;backward-compatibility guide&lt;/a&gt; contains the full attribute inventory and a per-change guide explaining which adaptations can already be made without dropping compatibility with the current Shopware version.&lt;/p&gt;

&lt;h2&gt;
  
  
  Static metadata does not replace runtime deprecations
&lt;/h2&gt;

&lt;p&gt;Not every compatibility problem should be left entirely to static analysis.&lt;/p&gt;

&lt;p&gt;If incompatible legacy usage can be detected when the method runs, Shopware still emits a conditional runtime deprecation. For example, when a parameter will be narrowed from &lt;code&gt;?string&lt;/code&gt; to &lt;code&gt;string&lt;/code&gt;, Core can detect that a caller still passes &lt;code&gt;null&lt;/code&gt; and trigger &lt;code&gt;Feature::triggerDeprecationOrThrow()&lt;/code&gt; for that call.&lt;/p&gt;

&lt;p&gt;This is more precise than deprecating the entire method. Callers already passing a string receive no warning, while callers depending on the behaviour that will break in 6.8 get an actionable message.&lt;/p&gt;

&lt;p&gt;Other changes cannot be detected reliably at runtime. A method cannot generally know that an extension overrides it with a future-incompatible declaration. A class becoming final cannot warn only the subclasses that matter without also creating noise for test doubles and other legitimate current usage.&lt;/p&gt;

&lt;p&gt;For those changes, structured static information is the better tool.&lt;/p&gt;

&lt;p&gt;Shopware’s PHPStan rules validate these announcements inside Core. They verify that parameter names and types resolve, that the announced state differs from the current state, and that runtime deprecations exist where incompatible use can be detected. Attributes also fail validation after their target version has arrived, so they cannot silently become stale documentation.&lt;/p&gt;

&lt;p&gt;A separate rule prevents the old &lt;code&gt;@deprecated reason:*&lt;/code&gt; planning markers from being reintroduced.&lt;/p&gt;

&lt;h2&gt;
  
  
  What becomes possible next
&lt;/h2&gt;

&lt;p&gt;The first benefit for extension projects requires no additional tooling: after updating to Shopware 6.7.14.0, Core’s internal planning notes no longer appear as generic deprecation errors.&lt;/p&gt;

&lt;p&gt;The structured metadata also allows us to go further.&lt;/p&gt;

&lt;p&gt;A forward-looking &lt;a href="https://github.com/shopware/phpstan-shopware/pull/43" rel="noopener noreferrer"&gt;proof of concept in &lt;code&gt;phpstan-shopware&lt;/code&gt;&lt;/a&gt; explores an opt-in future-compatibility ruleset. Instead of analysing only the declarations available today, it can interpret the announced contracts and check whether extension code is already compatible with the next major version.&lt;/p&gt;

&lt;p&gt;Such a ruleset can, for example, find:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Calls that pass values outside a future narrowed parameter type.&lt;/li&gt;
&lt;li&gt;Named arguments using a parameter’s old name.&lt;/li&gt;
&lt;li&gt;Overrides missing a future optional parameter.&lt;/li&gt;
&lt;li&gt;Classes extending something that will become final or internal.&lt;/li&gt;
&lt;li&gt;Code that does not handle a future widened return type.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This remains forward-looking work and is deliberately separate from the default PHPStan rules. Extension projects should be able to opt into stricter future-compatibility analysis when it fits their support strategy.&lt;/p&gt;

&lt;p&gt;The same metadata could be used as input for custom Rector rules. Instead of parsing free-form PHPDoc text, a rule can read a specific change type and its payload, then apply a focused migration. IDE inspections, LSP diagnostics, compatibility reports, and upgrade-note generators are other possible consumers.&lt;/p&gt;

&lt;p&gt;The important part is that we now have reliable input on which such tools can be built.&lt;/p&gt;

&lt;h2&gt;
  
  
  Stop ignoring deprecations
&lt;/h2&gt;

&lt;p&gt;When &lt;code&gt;@deprecated&lt;/code&gt; cries wolf often enough, developers stop listening. That was the real cost of using the same signal for both removals and internal BC planning: every false alarm made the next genuine deprecation easier to ignore.&lt;/p&gt;

&lt;p&gt;With the two concerns now separated, that excuse is gone. Extension developers should take three concrete actions.&lt;/p&gt;

&lt;h3&gt;
  
  
  Remove broad deprecation suppressions
&lt;/h3&gt;

&lt;p&gt;An &lt;code&gt;@deprecated&lt;/code&gt; annotation on a public Shopware Core API is actionable. The API will be removed or replaced, and extensions using it need to follow the documented migration path.&lt;/p&gt;

&lt;p&gt;Broad ignore patterns that hide Shopware deprecations should therefore be removed. They now risk hiding work that must be completed before the next major release.&lt;/p&gt;

&lt;p&gt;Review the remaining deprecation reports in your extension, identify the documented replacement, and treat the migration as required maintenance rather than optional cleanup.&lt;/p&gt;

&lt;h3&gt;
  
  
  Check BC-change attributes on the APIs you use
&lt;/h3&gt;

&lt;p&gt;Removing false warnings is only one half of the improvement. Extension developers also need to pick up the new BC-change signals.&lt;/p&gt;

&lt;p&gt;When an API used by your extension carries a BC-change attribute, check whether it applies to call sites, extenders, or both. Then compare the announced change with how your extension uses that API.&lt;/p&gt;

&lt;p&gt;The attributes do not make an extension forward-compatible by themselves. They provide the information needed to do so. If they are ignored until the major upgrade, the incompatibilities will still arrive all at once.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adopt forward-compatible declarations early
&lt;/h3&gt;

&lt;p&gt;Many announced changes can be handled before the next major release without dropping support for the current Shopware version.&lt;/p&gt;

&lt;p&gt;The examples above show the concrete benefit:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;An override can add an announced optional parameter today.&lt;/li&gt;
&lt;li&gt;An override can adopt an announced narrower return type today.&lt;/li&gt;
&lt;li&gt;A call site can stop relying on a parameter name that will change.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are not merely preparations written down for later. They are changes extension developers can make now. One implementation can remain backward-compatible with the current Shopware version while already being compatible with the announced future contract.&lt;/p&gt;

&lt;p&gt;Make these checks part of regular extension maintenance and static analysis instead of postponing them until the major upgrade. That turns one disruptive migration into a series of smaller, safer changes.&lt;/p&gt;

&lt;p&gt;Shopware 6.8 is the first major upgrade to benefit from this model, but it will not be the last. Future major changes can use the same structured announcements, while PHPStan, Rector, and other tools can become increasingly effective at turning them into concrete migration work.&lt;/p&gt;

&lt;p&gt;The goal is to stop &lt;code&gt;@deprecated&lt;/code&gt; from crying wolf. When it appears now, treat it as a warning that demands action. When a BC-change attribute appears, use the head start it provides.&lt;/p&gt;

</description>
      <category>shopware</category>
      <category>php</category>
      <category>deprecation</category>
    </item>
    <item>
      <title>How to update php-redis extension (and why you might need to do so during shopware updates)</title>
      <dc:creator>Jonas Elfering</dc:creator>
      <pubDate>Fri, 27 Feb 2026 09:00:00 +0000</pubDate>
      <link>https://dev.to/shopware/how-to-update-php-redis-extension-and-why-you-might-need-to-do-so-during-shopware-updates-9ma</link>
      <guid>https://dev.to/shopware/how-to-update-php-redis-extension-and-why-you-might-need-to-do-so-during-shopware-updates-9ma</guid>
      <description>&lt;p&gt;This post gives you an explanation on why you might need to update the php-redis when upgrading to the latest shopware versions and how you can do so hassle-free&lt;/p&gt;

&lt;h2&gt;
  
  
  Why you might need to update the &lt;code&gt;php-redis&lt;/code&gt; extension during shopware updates?
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://github.com/shopware/shopware/blob/trunk/RELEASE_INFO-6.7.md#symfony-74-update" rel="noopener noreferrer"&gt;latest shopware 6.7.7.0 version&lt;/a&gt; included the upgrade to Symfony LTS version 7.4. Because the previously used Symfony 7.3 version &lt;a href="https://symfony.com/releases#symfony-releases-calendar" rel="noopener noreferrer"&gt;stopped being actively supported in Jan 2026&lt;/a&gt;, shopwares 6.6 LTS version will receive the Symfony update as well as part of the next release. &lt;br&gt;
The update from Symfony 7.3 to 7.4 is only a minor upgrade, so it should not include any breaking changes. While that is true on the code level of Symfony itself, Symfony &lt;a href="https://github.com/symfony/symfony/blob/7.4/UPGRADE-7.4.md#cache" rel="noopener noreferrer"&gt;did increase the needed minimum version&lt;/a&gt; of the &lt;code&gt;php-redis&lt;/code&gt; extension to 6.1 as part of the minor update. So if you currently use an older version of the extension, you will need to update the extension in order to successfully update shopware. This might especially be the case if you rely on older versions of Linux distributions; the 24.04 LTS version of Ubuntu, for example, ships &lt;code&gt;php-redis&lt;/code&gt; extension in version 5.3, which is not compatible, and you need to take action to update the package accordingly. &lt;/p&gt;
&lt;h2&gt;
  
  
  How can I figure out which &lt;code&gt;php-redis&lt;/code&gt; version I'm currently running?
&lt;/h2&gt;

&lt;p&gt;You can check the installed version of &lt;code&gt;php-redis&lt;/code&gt; extension by running the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;php &lt;span class="nt"&gt;--re&lt;/span&gt; redis | &lt;span class="nb"&gt;head&lt;/span&gt; &lt;span class="nt"&gt;-1&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When that command indicates that you are running on version 6.1 or newer, you are ready to update to the latest shopware version without further action. If you're currently running an older version, you need to update it first.&lt;/p&gt;

&lt;p&gt;Additionally, Symfony added a composer conflict with older &lt;code&gt;php-redis&lt;/code&gt; versions, which means that the shopware upgrade (with the included Symfony upgrade) will throw a composer error if you still use an older version. &lt;/p&gt;

&lt;h2&gt;
  
  
  Should I update my &lt;code&gt;php-redis&lt;/code&gt; extension now?
&lt;/h2&gt;

&lt;p&gt;Generally, you should only look at upgrading &lt;code&gt;php-redis&lt;/code&gt; when you plan to upgrade to the latest shopware versions, which include the upgrade to Symfony 7.4. Upgrading the &lt;code&gt;php-redis&lt;/code&gt; version in existing, running applications provides no real benefit. And quite to the contrary, older shopware versions (especially when you are still on shopware 6.5) might not work with the latest &lt;code&gt;php-redis&lt;/code&gt; version. Therefore, you shouldn't upgrade just in case, only if you are affected and want to upgrade to the latest shopware versions that require this. This guide shouldn't be considered a general best practice, but rather a troubleshooting guide for when you're upgrading and run into the need to update the &lt;code&gt;php-redis&lt;/code&gt; extension.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to update the &lt;code&gt;php-redis&lt;/code&gt; extension in Docker
&lt;/h2&gt;

&lt;p&gt;Docker makes it easy to control the full environment; therefore, it is straightforward to update the &lt;code&gt;php-redis&lt;/code&gt; extension in your Dockerfile.&lt;/p&gt;

&lt;p&gt;First you should download the &lt;a href="https://github.com/mlocati/docker-php-extension-installer" rel="noopener noreferrer"&gt;php extension installer for Docker&lt;/a&gt; and make it executable:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;ADD&lt;/span&gt;&lt;span class="s"&gt; https://github.com/mlocati/docker-php-extension-installer/releases/latest/download/install-php-extensions /usr/local/bin/&lt;/span&gt;
&lt;span class="k"&gt;RUN &lt;/span&gt;&lt;span class="nb"&gt;chmod&lt;/span&gt; +x /usr/local/bin/install-php-extensions
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That script helps you to manage php extensions. &lt;/p&gt;

&lt;p&gt;Next you can install the &lt;code&gt;php-redis&lt;/code&gt; extension:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight docker"&gt;&lt;code&gt;&lt;span class="k"&gt;RUN &lt;/span&gt;install-php-extensions redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By default, that will install the latest stable version of the extension. It might be the case that you pinned the installed version, and you need to upgrade that:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt;&lt;span class="gd"&gt;-RUN install-php-extensions redis-6.0
&lt;/span&gt;&lt;span class="gi"&gt;+RUN install-php-extensions redis-6.3
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you use the &lt;a href="https://github.com/shopware/docker/pkgs/container/docker-base" rel="noopener noreferrer"&gt;official shopware/docker image&lt;/a&gt;, that update is already done automatically, and you just need to make sure that you update to the latest version of the image.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to update the &lt;code&gt;php-redis&lt;/code&gt; extension in Ubuntu
&lt;/h2&gt;

&lt;p&gt;You can install the &lt;code&gt;php-redis&lt;/code&gt; extension in Ubuntu through the default package manager:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; php-redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, depending on the Ubuntu version you are using, the extension available in the official package repository might be too old.&lt;/p&gt;

&lt;p&gt;In that case, you can install the package from the &lt;code&gt;ondrej/php&lt;/code&gt; package repository, which is the trusted source for pre-built php packages:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;add-apt-repository ppa:ondrej/php &lt;span class="c"&gt;# Press enter when prompted.&lt;/span&gt;
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt update
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that when you install the &lt;code&gt;php-redis&lt;/code&gt; extension it should pick up the latest version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;apt &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-y&lt;/span&gt; php-redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to install the extension locally (with PIE)
&lt;/h2&gt;

&lt;p&gt;There is a new extension installer in the PHP ecosystem called &lt;a href="https://www.php.net/manual/en/install.pie.intro.php" rel="noopener noreferrer"&gt;PIE&lt;/a&gt;. PIE makes installing extensions easier and installs the latest versions from Packagist. PIE is intended to replace the old PECL installer and works similarly to Composer. &lt;/p&gt;

&lt;p&gt;To install PIE follow the &lt;a href="https://github.com/php/pie/blob/1.4.x/docs/usage.md#installing-pie" rel="noopener noreferrer"&gt;installation instructions&lt;/a&gt; from the official repository:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;curl &lt;span class="nt"&gt;-fL&lt;/span&gt; &lt;span class="nt"&gt;--output&lt;/span&gt; /tmp/pie.phar https://github.com/php/pie/releases/latest/download/pie.phar &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; gh attestation verify &lt;span class="nt"&gt;--owner&lt;/span&gt; php /tmp/pie.phar &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo mv&lt;/span&gt; /tmp/pie.phar /usr/local/bin/pie &lt;span class="se"&gt;\&lt;/span&gt;
  &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class="nb"&gt;sudo chmod&lt;/span&gt; +x /usr/local/bin/pie
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When you have PIE installed, you can install the &lt;code&gt;php-redis&lt;/code&gt; extension by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pie &lt;span class="nb"&gt;install &lt;/span&gt;phpredis/phpredis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How to install the extension locally (with PECL)
&lt;/h2&gt;

&lt;p&gt;PECL is the old-school extension installer in the PHP ecosystem; setting it up is not as straightforward as PIE, so it is not recommended anymore. However, if you have already set up PECL, you can continue using that.&lt;/p&gt;

&lt;p&gt;If you have PECL set up, you can install the latest extension by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pecl &lt;span class="nb"&gt;install &lt;/span&gt;redis
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



</description>
      <category>php</category>
      <category>shopware</category>
      <category>redis</category>
      <category>upgrade</category>
    </item>
    <item>
      <title>Mocks and their Influence on Software Design</title>
      <dc:creator>Jonas Elfering</dc:creator>
      <pubDate>Fri, 08 Sep 2023 09:05:00 +0000</pubDate>
      <link>https://dev.to/shopware/mocks-and-their-influence-on-software-design-3o49</link>
      <guid>https://dev.to/shopware/mocks-and-their-influence-on-software-design-3o49</guid>
      <description>&lt;p&gt;When speaking about unit testing, one automatically also speaks about mocks and the need to mock away dependencies.&lt;/p&gt;

&lt;p&gt;It seems to be quite a typical attitude towards mocks along the lines of "Mock every external dependency of the class under test" and this attitude can be quite dangerous.&lt;/p&gt;

&lt;p&gt;Therefore, here are some words of caution on the implication that the heavy use of mocks in your code base can have in terms of the overall system design or architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;p&gt;Mocks are used to provide isolation in unit tests, and thus should help to create software that is &lt;strong&gt;easy to test&lt;/strong&gt; and &lt;strong&gt;easy to change&lt;/strong&gt;. But in fact, an over-usage of mocks in any unit test suite can cover up underlying issues in the software design that make the software &lt;strong&gt;hard to test&lt;/strong&gt; and &lt;strong&gt;hard to change&lt;/strong&gt;. So Mocks should be treated as one tool in your toolbox that one can use to build high-quality and maintainable software. That means one should know when to apply this specific tool, or when should rather use another tool from the toolbox.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mocks are hard to refactor
&lt;/h2&gt;

&lt;p&gt;Be cautious when utilizing mocks extensively because it can be hard to automatically refactor classes. This is because IDEs do not provide robust support for refactoring classes that are heavily mocked, and tools like &lt;a href="https://phpstan.org/"&gt;PHPStan&lt;/a&gt; may not effectively detect these mock-related issues.&lt;/p&gt;

&lt;p&gt;More broadly speaking, it is hard to guarantee that the mock behaves in the same/or intended manner as the real implementation (especially when the underlying implementation changes).&lt;/p&gt;

&lt;p&gt;Use mocks only where you need to because:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;creating the objects is hard as you need tons of nested dependencies to create the object.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;or&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;the class produces some side effects that you don't want in unit tests (e.g., DB writes).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For all other cases, use real implementations and rely as minimally as possible on the magic of PHPUnit's mocking framework.&lt;/p&gt;

&lt;h3&gt;
  
  
  Focus on behavior, not implementation: Effective unit testing principles
&lt;/h3&gt;

&lt;p&gt;Relying heavily on mocks creates a bad pattern in unit tests of testing &lt;strong&gt;how&lt;/strong&gt; something is implemented and not &lt;strong&gt;what&lt;/strong&gt; the implementation actually does. If tests are implemented in a mock-heavy way, they are tightly coupled to the implementation, meaning they rely on implementation details and may fail more often when the implementation details change than when the actual behavior of the class under test changes. Consider these two example changes to some classes:&lt;/p&gt;

&lt;p&gt;Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;search&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$criteria&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;first&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;?-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getId&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;searchIds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$criteria&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;firstId&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Before:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;fetchAllAssociative&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'SELECT first, second FROM foo ...'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nv"&gt;$values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;mapToKeyValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$values&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$values&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;connection&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;fetchKeyValue&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'SELECT first, second FROM foo ...'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By definition, both changes are a pure example of refactoring:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Refactoring is a disciplined technique for restructuring an existing body of code, altering its internal structure without changing its external behavior.&lt;br&gt;
-&amp;gt; &lt;a href="https://refactoring.com/"&gt;Martin Fowler&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But when the unit test mocked the &lt;code&gt;repository&lt;/code&gt; or &lt;code&gt;connection&lt;/code&gt; dependencies, the unit tests will fail after the change, even though the external behaviour (that's what a test should really test) was not changed.&lt;/p&gt;

&lt;p&gt;Using mocks is ok in some cases, but not all.&lt;/p&gt;

&lt;p&gt;Probably the examples from above are ones that are totally valid (as the mocked classes rely on a DB), which can be commonly encountered in real life.&lt;/p&gt;

&lt;p&gt;Furthermore, the intention of this document is to keep you aware of the downsides that come with using mocks.&lt;/p&gt;

&lt;h2&gt;
  
  
  Mocks might indicate your class is not well-designed
&lt;/h2&gt;

&lt;p&gt;In a well-designed and testable system, it is relatively easy to isolate individual classes or modules and distinguish them between the components that contain the core business logic, which should be extensively unit tested, and the portions responsible for interfacing with the external environment and generating side effects. These side-effect-prone elements should be substituted in the unit tests. In fact, it is advisable to perform integration testing since their primary purpose is to abstract and facilitate the replacement of side effects in tests.&lt;/p&gt;

&lt;p&gt;This kind of abstraction follows when you apply the principles of &lt;a href="https://martinfowler.com/bliki/DomainDrivenDesign.html"&gt;Domain Driven Design&lt;/a&gt; and &lt;a href="https://alistair.cockburn.us/hexagonal-architecture/"&gt;Hexagonal Architecture&lt;/a&gt; (aka Ports &amp;amp; Adapters). I've written in more detail about those architectural considerations in my &lt;a href="https://dev.to/shopware/benefits-of-separating-core-code-from-infrastructure-code-302j"&gt;previous post&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The absence of such abstraction in an existing codebase is one of the reasons why it can be quite hard to write "good" unit tests.&lt;/p&gt;

&lt;p&gt;So, a heavy reliance on mocks when writing unit tests can indicate a potential issue with the software design, suggesting insufficient encapsulation. Hence, designing code to promote better encapsulation and reduce the need for extensive mocking is advisable. This can lead to improved testability and overall software quality.&lt;/p&gt;

&lt;h2&gt;
  
  
  Better options than mocks
&lt;/h2&gt;

&lt;p&gt;There are better options, but that depends on the use cases. Here are a few alternatives:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Use the real implementation (this means the real dependency is easy to create and does not produce side effects)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Use a hand-crafted dummy implementation of the real dependency, that is easy to configure and behaves like a stub in that use case (this means that the real dependency probably needs to be designed in a way to be easy to replace)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Fallback to using a mocking framework (when the real dependency is not designed to be replaced easily)&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The way you design your codebase directly impacts whether you can rely on option 1 or option 2 without resorting to heavy mocking.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: Write tests first!
&lt;/h2&gt;

&lt;p&gt;When you write tests first, most of the points described above should come out of the box!&lt;/p&gt;

&lt;p&gt;Nobody who starts with a test would start with configuring a mock.&lt;/p&gt;

&lt;p&gt;While we provide insights on this, it is essential to validate the information. So we encourage you to explore the following references to gain a deeper understanding and form your own opinion.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;p&gt;Frank De Jonge on the exact same topic (with more examples in PHP): &lt;a href="https://blog.frankdejonge.nl/testing-without-mocking-frameworks/"&gt;https://blog.frankdejonge.nl/testing-without-mocking-frameworks/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Martin Fowler on the differences between mocks (option 3) and stubs (option 2): &lt;a href="https://martinfowler.com/articles/mocksArentStubs.html"&gt;https://martinfowler.com/articles/mocksArentStubs.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Presentation by Mathias Noback on testing hexagonal architectures: &lt;a href="https://matthiasnoback.nl/talk/a-testing-strategy-for-hexagonal-applications/"&gt;https://matthiasnoback.nl/talk/a-testing-strategy-for-hexagonal-applications/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Some good real-life examples on unit tests in php: &lt;a href="https://github.com/sarven/unit-testing-tips"&gt;https://github.com/sarven/unit-testing-tips&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A great write-up on testing in general: &lt;a href="https://dannorth.net/2021/07/26/we-need-to-talk-about-testing/"&gt;https://dannorth.net/2021/07/26/we-need-to-talk-about-testing/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Quite an old (1997!) paper on how &lt;strong&gt;not&lt;/strong&gt; to use code coverage: &lt;a href="http://www.exampler.com/testing-com/writings/coverage.pdf"&gt;http://www.exampler.com/testing-com/writings/coverage.pdf&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Great blog post series on how to avoid mocks: &lt;a href="https://philippe.bourgau.net/categories/#how-to-avoid-mocks-series"&gt;https://philippe.bourgau.net/categories/#how-to-avoid-mocks-series&lt;/a&gt;&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>php</category>
      <category>architecture</category>
      <category>testing</category>
    </item>
    <item>
      <title>Benefits of separating core code from infrastructure code</title>
      <dc:creator>Jonas Elfering</dc:creator>
      <pubDate>Thu, 31 Aug 2023 12:54:00 +0000</pubDate>
      <link>https://dev.to/shopware/benefits-of-separating-core-code-from-infrastructure-code-302j</link>
      <guid>https://dev.to/shopware/benefits-of-separating-core-code-from-infrastructure-code-302j</guid>
      <description>&lt;p&gt;When it comes to software design and software architecture, there are many theoretical approaches with fancy acronyms (like &lt;a href="https://en.wikipedia.org/wiki/SOLID"&gt;SOLID&lt;/a&gt;, &lt;a href="https://dannorth.net/2022/02/10/cupid-for-joyful-coding/"&gt;CUPID&lt;/a&gt;, &lt;a href="https://martinfowler.com/bliki/DomainDrivenDesign.html"&gt;DDD&lt;/a&gt;, &lt;a href="https://alistair.cockburn.us/hexagonal-architecture/"&gt;hexagonal architecture&lt;/a&gt;, &lt;a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html"&gt;clean architecture&lt;/a&gt;, …). However, it is not always easy to translate these concepts into the practical world, and it is not clear where they overlap or not. Therefore, it's important to think about the practices all academic design patterns have in common and start from &lt;a href="https://fs.blog/first-principles/"&gt;first principles&lt;/a&gt;. One really concrete practice that is encouraged by almost all software design flavors is the separation of core and infrastructure code. This post will explore many of the benefits and challenges through a real-life, practical example, so that by the end you will have a better understanding of how and why any software system might implement this tenant of sustainable architecture.&lt;/p&gt;

&lt;h2&gt;
  
  
  What is core and what is infrastructure code anyways?
&lt;/h2&gt;

&lt;p&gt;Every software system consists of core and infrastructure code. Infrastructure code, in simple terms, is the code that connects the main business logic (core code) to the outside world (e.g. to the web server or database). For a definition of core code, we can refer to &lt;a href="https://matthiasnoback.nl/"&gt;Matthias Noback's&lt;/a&gt; book “&lt;a href="https://matthiasnoback.nl/book/advanced-web-application-architecture/"&gt;Advanced Web Application Architecture&lt;/a&gt;”:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Rule 1:&lt;br&gt;
Core code doesn’t directly depend on external systems, nor does it depend on code written for interacting with a specific type of external system.&lt;br&gt;
Rule 2:&lt;br&gt;
Core code doesn’t need a specific environment to run in, nor does it have dependencies that are designed to run in a specific context only.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;A common symptom of weak software design is if, at the code level, it is difficult to distinguish between the two. This lack of separation reflects a web of dependencies that create a host of issues, all of which we will gradually walk through with the example, below.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For the purpose of this blog post, Infrastructure code should not be confused with “Infrastructure as Code” (the code needed to spin up the server/cloud infrastructure that the application runs on).&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  An example
&lt;/h2&gt;

&lt;p&gt;Consider the following &lt;a href="https://symfony.com/"&gt;Symfony&lt;/a&gt; controller used to post a new review by a customer for a given product:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;#[Route(path: '/store-api/product/{productId}/review', methods: ['POST']]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="kt"&gt;RequestDataBag&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="kt"&gt;SalesChannelContext&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;NoContentResponse&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/** @var CustomerEntity $customer */&lt;/span&gt;
    &lt;span class="nv"&gt;$customer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getCustomer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nv"&gt;$customerId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getId&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getFirstName&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'lastName'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'lastName'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getLastName&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'customerId'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'productId'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

    &lt;span class="nv"&gt;$review&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
        &lt;span class="s1"&gt;'productId'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'customerId'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'externalUser'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="s1"&gt;'content'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'content'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="s1"&gt;'points'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'points'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="s1"&gt;'status'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;];&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$review&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;upsert&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nv"&gt;$review&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;eventDispatcher&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ReviewFormEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NoContentResponse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code is rather straight forward to read: the controller accepts some data, fills in some fall-back data based on the customer currently logged-in, validates the input, saves the review to the database and dispatches a domain event. In a nutshell, this controller does too much at once. Through the course of this post, we will use this example to study the problems this can cause, and gradually refactor it to illustrate how separating the core code from infrastructure code inherently minimizes these issues or resolves them entirely.&lt;/p&gt;

&lt;h2&gt;
  
  
  Evolve infrastructure and core independently
&lt;/h2&gt;

&lt;p&gt;Over time, your understanding of the underlying domain you are working in will improve, and you naturally will update your business logic to reflect this learning. In the best case, you want to have a single place where this knowledge is stored. On the other hand, if you want to grow your business, there may be other use cases where you want to provide the same business functionality (posting reviews) in different contexts. So there is a need for the infrastructure code and the core code to be able to evolve independently.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reusability
&lt;/h3&gt;

&lt;p&gt;In the controller example above, one can easily imagine that a new business requirement may arise that a merchant should be able to bulk import reviews from an existing review system. In the current implementation, this is not easily possible, because all the code is in a single place and it is not really reusable. In this scenario, the same business rules should apply, and the same domain events should be dispatched, because for the core domain logic, it is probably not that important from which source a new review was posted. Instead of copy &amp;amp; pasting a bunch of code to make the new use case work, the better option would be to separate the domain logic that is responsible for posting a review from the controller that provides that functionality over an HTTP-API. &lt;/p&gt;

&lt;p&gt;So our code may now look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;#[Route(path: '/store-api/product/{productId}/review', methods: ['POST'])]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="kt"&gt;RequestDataBag&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="kt"&gt;SalesChannelContext&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;NoContentResponse&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/** @var CustomerEntity $customer */&lt;/span&gt;
    &lt;span class="nv"&gt;$customer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getCustomer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nv"&gt;$customerId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getId&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getFirstName&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'lastName'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'lastName'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getLastName&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'customerId'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'productId'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;postProductReviewService&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NoContentResponse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PostProductReviewService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;RequestDataBag&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Context&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$review&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'productId'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'productId'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'customerId'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'customerId'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'externalUser'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'content'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'content'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'points'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'points'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'status'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;];&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$review&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;upsert&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nv"&gt;$review&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;eventDispatcher&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ReviewFormEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that structure in place, it is now rather easy to implement the “Bulk Import Reviews” functionality, by reusing the extracted service. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; The new core service still expects a &lt;code&gt;RequestDataBag&lt;/code&gt; parameter, which is not optimal but will be tackled further down.&lt;/p&gt;

&lt;p&gt;This refactoring step also greatly helps in cases when there comes a requirement for additional validation, that a customer actually has purchased the product in the past before the review is saved. After the refactoring, there is a single place where that logic can be added and we can evolve the core code independently from the infrastructure.&lt;/p&gt;

&lt;h3&gt;
  
  
  Switching the underlying technology
&lt;/h3&gt;

&lt;p&gt;Another case where infrastructure code may change but the core code should not be affected is when there is the need to switch the underlying technology. There is much talk about being able to (theoretically) switch the whole data storage layer for the complete application without affecting the core code. I have to admit that I have never seen that work out in real life, and I think that these kinds of replacements should not be our end goal, as such an application probably would be over-engineered. But the possibility to switch out underlying technology for specific parts of the application without having to touch the rest of the system can be a sweet spot. &lt;/p&gt;

&lt;p&gt;Back to our code example, perhaps some requirement arises where product reviews should not be saved in the relational database, but rather posted to an external review system that should be integrated. To make this change easier, the code that actually takes care of saving the data should be extracted from the core service (as that is actually infrastructure code) and an interface should be introduced, so that the core service only relies on the interface. &lt;/p&gt;

&lt;p&gt;The code could be refactored like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PostProductReviewService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;RequestDataBag&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Context&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;productReviewGateway&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;postReviewByCustomer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;eventDispatcher&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ReviewFormEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'productId'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'customerId'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;ProductReviewGateway&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;postReviewByCustomer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;RequestData&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Context&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DalProductReviewDataGateway&lt;/span&gt; &lt;span class="kd"&gt;implements&lt;/span&gt; &lt;span class="nc"&gt;ProductReviewGateway&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;postReviewByCustomer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;ProductReviewPostData&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;ProductReviewStatus&lt;/span&gt; &lt;span class="nv"&gt;$status&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Context&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$review&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
            &lt;span class="s1"&gt;'productId'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'productId'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'customerId'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'customerId'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'externalUser'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'content'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'content'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'points'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'points'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="s1"&gt;'status'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="kc"&gt;false&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="p"&gt;];&lt;/span&gt;

        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="nv"&gt;$review&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;repository&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;upsert&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nv"&gt;$review&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The fact that we use the &lt;a href="https://developer.shopware.com/docs/concepts/framework/data-abstraction-layer"&gt;Shopware DAL&lt;/a&gt; to store the reviews is now an implementation detail. We can easily change that storage layer without having to touch the core business logic.&lt;/p&gt;

&lt;h3&gt;
  
  
  Caveat: Finding the right abstractions
&lt;/h3&gt;

&lt;p&gt;When creating abstractions to hide technical decisions from the consumer of that code, a major challenge is defining the right level of abstraction. &lt;/p&gt;

&lt;p&gt;On the one hand, it is easy to create an “abstraction” that is too specific and tightly coupled to the implementation by &lt;a href="https://en.wikipedia.org/wiki/Leaky_abstraction"&gt;leaking technical details as part of the interface&lt;/a&gt;. This leads to a situation where even if there is an abstraction in place, it is not possible to switch the actual implementation without breaking the abstraction.&lt;/p&gt;

&lt;p&gt;On the other hand, it might also happen that abstractions are too generic. If that is the case, then clients of the abstraction have to implement solutions for common cases that are actually better solved by the implementation of that abstraction.&lt;/p&gt;

&lt;p&gt;So finding the right level of abstraction is always a trade-off between either too specific or too general.&lt;/p&gt;

&lt;h2&gt;
  
  
  Testability
&lt;/h2&gt;

&lt;p&gt;Being able to easily write unit tests for your mission critical business logic is a prerequisite in order to deliver high-quality software. If the infrastructure and the core code are not separated, it is hard to write these unit tests, as basically the whole system has to be in place in order to perform them. Looking back at the original single controller example from the beginning, in order to write a test for that piece of code, a database needs to be set up, the Shopware DAL needs to be functional, which means that the Symfony container must be set up properly, and you have to fake a request in order for the tests to run at all.&lt;/p&gt;

&lt;p&gt;We can already see that the refactoring we made in order to evolve the infrastructure separately from the core code already improves testability a lot, as we can now test the infrastructure code and the core code separately. The core code is especially easier to test, as we don’t need to have a running database and the Symfony container set up anymore; instead, we can use a Mock or dummy implementation of our &lt;code&gt;ProductReviewGateway&lt;/code&gt; interface. The only thing that makes unit testing of our core code (the &lt;code&gt;PostProductReviewService&lt;/code&gt;) harder than it needs to be is the dependency on an HTTP-Request in the form of the &lt;code&gt;RequestDataBag&lt;/code&gt; argument. In order to make it easier to test, we can define a &lt;a href="https://martinfowler.com/eaaCatalog/dataTransferObject.html"&gt;DTO&lt;/a&gt; that encapsulates the actual parameters that our service needs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductReviewPostData&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$points&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;fromRequestData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="kt"&gt;RequestDataBag&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'content'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'points'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This DTO object can in itself be easily unit tested, and the adjusted service is now also easier to test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PostProductReviewService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;ProductReviewPostData&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Context&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;productReviewGateway&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;postReviewByCustomer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;eventDispatcher&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ReviewFormEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getProductId&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getCustomerId&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not only is the service now easier to test, but it is also easier to consume the service API as the expected input parameters are now well defined in the DTO, and there is no need anymore to guess the parameters and their names based on the implementation. Additionally, the type system gives us some simple validation for free, like validating required and optional parameters as well as their basic types.&lt;/p&gt;

&lt;p&gt;The controller now looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;#[Route(path: '/store-api/product/{productId}/review', methods: ['POST'])]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="kt"&gt;RequestDataBag&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="kt"&gt;SalesChannelContext&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;NoContentResponse&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/** @var CustomerEntity $customer */&lt;/span&gt;
    &lt;span class="nv"&gt;$customer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getCustomer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nv"&gt;$customerId&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getId&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getFirstName&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'lastName'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;set&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'lastName'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getLastName&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="nv"&gt;$postData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ProductReviewPostData&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;fromRequestData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;postProductReviewService&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$postData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NoContentResponse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The influence on complexity
&lt;/h2&gt;

&lt;p&gt;In order to keep a system in a state where it can be easily changed and evolved based on current needs, it is essential to keep the complexity of the overall system low. In general, the more things the system does, the more complex it becomes, but separating core from infrastructure code will help to keep complexity minimal. To see how many different things our original code does, we can separate it into the following “concerns”:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;How are the HTTP-Request parameters transformed so our application can handle them? (Infrastructure concern)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;What business rules apply when a product review is posted? (Core concern)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;How is a product review stored in a persistent storage? (Infrastructure concern)&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Our initial code handled all three concerns at the same time. That means when you want to understand how one of those concerns is solved, the code related to the other concerns is in fact adding complexity, which makes the part of the code you are actually interested in harder to understand. By separating out the concerns and handling them separately, it is easier to focus on one of the concerns without having to care how the others are solved; the level of complexity is reduced to a minimum. &lt;/p&gt;

&lt;p&gt;We can even improve our code a little bit further by moving the fallback handling (which gets the name from the currently logged-in customer) to where the rest of the DTO is created to have that in a single place as well. So the code might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="c1"&gt;#[Route(path: '/store-api/product/{productId}/review', methods: ['POST'])]&lt;/span&gt;
&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;save&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="kt"&gt;RequestDataBag&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="kt"&gt;SalesChannelContext&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;
&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;NoContentResponse&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="cd"&gt;/** @var CustomerEntity $customer */&lt;/span&gt;
    &lt;span class="nv"&gt;$customer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getCustomer&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

    &lt;span class="nv"&gt;$postData&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;ProductReviewPostData&lt;/span&gt;&lt;span class="o"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;fromRequestData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;postProductReviewService&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$postData&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getContext&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NoContentResponse&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductReviewPostData&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$points&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;fromRequestData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="kt"&gt;CustomerEntity&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="kt"&gt;RequestDataBag&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getFirstName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$lastName&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'lastName'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getLastName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getId&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'content'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'points'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With that refactoring, it’s now obvious we added a &lt;code&gt;lastName&lt;/code&gt; field to the request based on the logged-in user, in case it was not provided by the client. But we actually never used &lt;code&gt;lastName&lt;/code&gt; anywhere when storing the review; the product review does not distinguish between first and last names, and has only one name field. So in the original code, there lay a bug in plain sight, but it was hidden by all the accidental complexity surrounding it. By separating the different concerns, the bug becomes obvious and easy to fix.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductReviewPostData&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;__construct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$content&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="k"&gt;private&lt;/span&gt; &lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nv"&gt;$points&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;static&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;fromRequestData&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="kt"&gt;CustomerEntity&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="kt"&gt;RequestDataBag&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;self&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getFirstName&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getLastName&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;self&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nv"&gt;$customer&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getId&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="nv"&gt;$name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'content'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
            &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'points'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Improvements in collaboration
&lt;/h2&gt;

&lt;p&gt;Another big benefit of separating core code from infrastructure code is that it can help you improve the collaboration with the non-engineers in your team, be it QA, designers or the people from the business side. When you separate the infrastructure-related code from the core code, it is way easier to see how the business rules for your application are implemented and if they match what the domain experts would expect. In the example case, some of the most interesting parts of the code are quite hidden in the &lt;code&gt;$this-&amp;gt;validate($data, $context)&lt;/code&gt; call. That method currently looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;ProductReviewPostData&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Context&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nv"&gt;$definition&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;DataValidationDefinition&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'product.create_rating'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

    &lt;span class="nv"&gt;$definition&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'name'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NotBlank&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
    &lt;span class="nv"&gt;$definition&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'content'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;NotBlank&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Length&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="s1"&gt;'min'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="mi"&gt;40&lt;/span&gt;&lt;span class="p"&gt;]));&lt;/span&gt;
    &lt;span class="nv"&gt;$definition&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'points'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;GreaterThanOrEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;LessThanOrEqual&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

    &lt;span class="nv"&gt;$criteria&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Criteria&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
    &lt;span class="nv"&gt;$criteria&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;addFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EqualsFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'customerId'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;customerId&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
    &lt;span class="nv"&gt;$criteria&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;addFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EqualsFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'productId'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;productId&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

    &lt;span class="c1"&gt;// ensure that the customer can only post one review per product&lt;/span&gt;
    &lt;span class="nv"&gt;$definition&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;add&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'id'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EntityNotExists&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;
        &lt;span class="s1"&gt;'entity'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'product_review'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'context'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="s1"&gt;'criteria'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nv"&gt;$criteria&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;]));&lt;/span&gt;

    &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;validator&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;validate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$definition&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The code uses the &lt;a href="https://symfony.com/doc/current/validation.html"&gt;Symfony validator&lt;/a&gt; component to perform the validation. The first part of the validation is rather straightforward: it performs some basic consistency checks on the data, e.g. that the name is filled, that the content of the review is at least 40 characters long and that the rating points are between one and five. With the new code structure, it would probably be best to move this part of the validation to the DTO object itself, so that it is not even possible to create a DTO that is invalid. One can still use the Symfony validator or perform those checks manually in the constructors. &lt;/p&gt;

&lt;p&gt;But the more interesting part is the last part of the code. There it uses some Shopware DAL magic to validate that the customer has not already reviewed the same product. This is a core business rule that should be enforced, but for now it is quite hidden in the validation code. To bring it into plain sight, we want to move this check into the body of the service, as that method should read like a workflow of what happens when a review is posted. To do so, we first create a new Interface for this kind of check, as only the Infrastructure layer can provide the information we need in the service, but those two layers should be kept separate. The interface might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;ProductReviewConstraints&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;hasCustomerAlreadyReviewedProduct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="kt"&gt;Context&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;
    &lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And the implementation using the Shopware DAL might look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DALProductReviewConstraints&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;hasCustomerAlreadyReviewedProduct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="kt"&gt;string&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="kt"&gt;Context&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;
    &lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;bool&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nv"&gt;$criteria&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;Criteria&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
        &lt;span class="nv"&gt;$criteria&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;addFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EqualsFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'productId'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$productId&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;
        &lt;span class="nv"&gt;$criteria&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;addFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;EqualsFilter&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'customerId'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$customerId&lt;/span&gt;&lt;span class="p"&gt;));&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;productReviewRepository&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;searchIds&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$criteria&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;firstId&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;!==&lt;/span&gt; &lt;span class="kc"&gt;null&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The business rule that says a customer can only post a review for a product once is now more obvious in the domain flow:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;PostProductReviewService&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;public&lt;/span&gt; &lt;span class="k"&gt;function&lt;/span&gt; &lt;span class="n"&gt;post&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kt"&gt;ProductReviewPostData&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kt"&gt;Context&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt; &lt;span class="kt"&gt;void&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;reviewConstraints&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;hasCustomerAlreadyReviewedProduct&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getProductId&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getCustomerId&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt;
            &lt;span class="nv"&gt;$context&lt;/span&gt;
        &lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;throw&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;CustomerAlreadyReviewedProductException&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getCustomerId&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getProductId&lt;/span&gt;&lt;span class="p"&gt;());&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;productReviewGateway&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;postReviewByCustomer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

        &lt;span class="nv"&gt;$this&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="n"&gt;eventDispatcher&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;dispatch&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
            &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;ReviewFormEvent&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getProductId&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;getCustomerId&lt;/span&gt;&lt;span class="p"&gt;(),&lt;/span&gt; &lt;span class="nv"&gt;$data&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nv"&gt;$context&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;With a structure like that, it is easy to discuss with other peers if we actually implemented the requirements the right way or if there is something missing. It is easy to spot that there is no check in place whether the customer actually bought that product or not, so it can spark discussions about whether and how to add such an additional check.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion: Keep infrastructure code at the boundaries of your codebase
&lt;/h2&gt;

&lt;p&gt;The code as we left it at the end of this post is by no means perfect, but it is a perfect starting point for further refactoring based on the advanced architecture patterns mentioned in the beginning (&lt;a href="https://martinfowler.com/bliki/DomainDrivenDesign.html"&gt;DDD&lt;/a&gt;, &lt;a href="https://alistair.cockburn.us/hexagonal-architecture/"&gt;hexagonal architecture&lt;/a&gt;, &lt;a href="https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architecture.html"&gt;clean architecture&lt;/a&gt;, …). For example, proponents of DDD probably would refactor the service in a way to encapsulate the business logic inside a rich domain model and not let it stay directly in the service itself. But especially in DDD, you also don’t want any outside dependencies in your domain model, so it’s a necessary step to first separate your core code from the infrastructure code.&lt;/p&gt;

&lt;p&gt;By now, this example walkthrough should already explain a lot of the benefits of separating the two. It makes it easier to interact with and evolve the codebase for you and your peers even when the requirements or the technology might considerably change. Ultimately, this is a general pattern that should be applied regardless of the architecture you have in place in your application, as it lays a concrete foundation for quality, sustainability and, dare I suggest, pleasure to work within your codebase.&lt;/p&gt;

</description>
      <category>architecture</category>
      <category>webdev</category>
      <category>php</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
