Skip to content

Make FileParser::parse() return directly a result instead of relying on getters and internal state#600

Merged
micheleorselli merged 9 commits intomainfrom
make-parse-return-result
Mar 28, 2026
Merged

Make FileParser::parse() return directly a result instead of relying on getters and internal state#600
micheleorselli merged 9 commits intomainfrom
make-parse-return-result

Conversation

@micheleorselli
Copy link
Copy Markdown
Member

@micheleorselli micheleorselli commented Mar 23, 2026

Preliminary step to make the introduction of a cache on parsing.

Replace the void return type with a ParserResult class containing:

  • ClassDescriptions: successful parse result (iterable collection)
  • ParsingErrors: PHP parser reported syntax errors

…icError

Replace the void return type and side-effect getters with a union return type:
- ClassDescriptions: successful parse result (iterable collection)
- ParsingErrors: PHP parser reported syntax errors
- GenericError: unexpected exception caught during parsing

Add ClassDescriptions and GenericError value types; update all callers
(Runner, DebugExpression) and fix tests that relied on the parser's
error-recovery traversal to tolerate invalid PHP syntax.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 23, 2026

Codecov Report

❌ Patch coverage is 99.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 98.31%. Comparing base (2cc17d0) to head (7843a3e).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/Analyzer/FileParser.php 93.33% 1 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #600      +/-   ##
============================================
+ Coverage     98.13%   98.31%   +0.18%     
- Complexity      666      681      +15     
============================================
  Files            84       86       +2     
  Lines          1930     1960      +30     
============================================
+ Hits           1894     1927      +33     
+ Misses           36       33       -3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@micheleorselli micheleorselli marked this pull request as ready for review March 24, 2026 23:25
@micheleorselli micheleorselli requested a review from fain182 March 24, 2026 23:25
@@ -4,26 +4,23 @@

namespace Arkitect\Tests\Unit\Rules;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the namespace needs to be updated

@fain182
Copy link
Copy Markdown
Collaborator

fain182 commented Mar 26, 2026

I like this PR, I have just a couple of doubts:
the classdescriptionS and parsingErrorS classes are needed?
I saw that you added the __toString() to parsingError, it's a good idea, maybe we could remove the getters now?

return new self($classDescriptions, $parsingErrors);
}

public static function withClassDescriptions(ClassDescriptions $classDescriptions): self
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

questa è usata solo nei test, probabilmente può saltare

@micheleorselli
Copy link
Copy Markdown
Member Author

like this PR, I have just a couple of doubts:
the classdescriptionS and parsingErrorS classes are needed?

I do like the idea of having collections classes instead of plain arrays, if anything, there are less comments to spread around to make static analysis tool happy

I saw that you added the __toString() to parsingError, it's a good idea, maybe we could remove the getters now?

gone

@micheleorselli micheleorselli merged commit 9498feb into main Mar 28, 2026
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants