Urgent.News

What's breaking now, across thousands of outlets.

Tech

Your architecture rules are code too: mutation-testing a DDD ruleset in PHP 8.4

In September 2017 Lukas Taake published the first part of a write-up of his master's thesis about static code analysis for Domain-Driven Design. It was built as a SonarQube plugin for Java, and its thesis is the most honest sentence in the genre: static analysis cannot show that DDD is done correctly; it can help keep some basic principles intact over time. I wanted to know what that looks like…

In September 2017, Lukas Taake published the first part of his master's thesis on static code analysis for Domain-Driven Design (DDD) as a SonarQube plugin for Java. Taake's rules for DDD were based on class hierarchy, name patterns, and annotations, but he acknowledged the limitations of this approach: the tool could only help maintain basic principles over time, and it could not prove that DDD was correctly implemented. Taake revisited these rules in PHP 8.4, where attributes provide a natural way to enforce them.

The PHP 8.4 implementation follows Taake's eight rules:

1. Every entity type has an identity.

2. Value objects are immutable.

3. No anemic domain model (entities that are only getters and setters).

4. Aggregates are trees and link to other aggregates only by identity.

5. An aggregate has a maximum size.

6. Domain services exist only where behavior cannot sit in an entity.

7. Repository implementations live outside the domain model.

8. The domain model depends on nothing else in the application.

Taake created PHP classes to represent entities, aggregates, and value objects, using attributes to identify their types. He implemented these classes using PHP 8.4 features, such as readonly properties, asymmetric visibility, and attributes. The demo domain includes two aggregate roots, Customer and Order, with value objects for Money, IDs, and Order numbers. Customer and Order refer to each other by their respective IDs, adhering to rule 4.

Taake also created a PHPStan rule to check that aggregates do not contain other aggregates, which is necessary because PHP's language features do not enforce this rule directly. He used PHPStan version 2.3.5 for this purpose. The demo domain uses PHP 8.4.16, PHPStan 2.3.5, phpat 0.12.5, Deptrac 4.7.2, and PHP Arikitect 1.3.1.

Taake highlights the value of mutation testing, which asks whether a set of checks would catch a rule violation if one were introduced. He tested his PHP implementation with mutants and found that the checks generally caught the issues, demonstrating the effectiveness of the rules in PHP 8.4.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Your Scripts Assume git init Creates master and Git 3.0 Will Make It main

A new developer joined and ran the tests. Fourteen failed on her laptop and passed in CI. All of them in the same file. The tests built little repositories to try the release tool on.

  • Tests failed on developer's laptop due to missing master branch
  • Git default branch name changed to main in 2020
  • Scripts should explicitly name branches using git init -b

You Saved the Stuck Design Problem for Your Sharpest Hour and It Would Not Move

You know when you are sharpest. For you it is nine to eleven, coffee in, messages off. So that is where you put the hard thing. The design problem you had been stuck on for a week.

  • Individual struggled with design problem for a week during peak hours.
  • Solution emerged at 4:30 PM on Thursday, during off-peak hours.
  • Research suggests tackling insight problems during off-peak hours can be effective.

You Did Most of the Work on That Project and So Did Everyone Else

The retro was polite. Everybody said it had been a team effort. Afterwards, over coffee, three people told you, separately, the same thing. Honestly, I carried that one. Each of them meant it.

  • Each person independently estimated their contribution to household chores.
  • Combined total of contributions exceeded the entire task.
  • Recognizing others' contributions alleviates perceived burden.

Your Manager Rewrites Every Document Before It Goes Out

You spent most of the week on the proposal. You sent it to your manager on Thursday, and on Friday the version that went to the directors was almost unrecognisable.

  • Manager extensively rewrites documents before distribution
  • Frequent edits cause self-doubt and questioning of writing abilities
  • Recognize patterns in changes to communicate with manager

Ssangyong E&C Secures Potential KRW 3.6 Trillion Dubai Development Pipeline

Ssangyong Engineering & Construction has entered into a strategic partnership with Dubai-based Wasl Group, securing a potential development project pipeline worth approximately KRW 3.6 trillion over…

  • Ssangyong E&C partners with Dubai-based Wasl Group.
  • Potential KRW 3.6 trillion development pipeline over three years.
  • Collaboration includes residential, hotels, and mixed-use projects.

Kolmar Korea’s Targeted Anti-Aging Material Earns NET Certification

Kolmar Korea’s antioxidant material technology, developed jointly with a research team at Jeonbuk National University, has received New Excellent Technology (NET) certification from the Ministry of…

  • Kolmar Korea develops targeted anti-aging material TOT with Jeonbuk National University.
  • TOT selectively releases vitamin E in response to hydrogen peroxide, reducing oxidative stress.
  • NET certification from Ministry of Trade, Industry and Energy validates advanced technology.

More from Thursday 5 November →