Skip to content

Fix existing inline PHP snippets#3206

Open
mnocon wants to merge 1 commit into
test-php-snippetsfrom
fix-php-snippets
Open

Fix existing inline PHP snippets#3206
mnocon wants to merge 1 commit into
test-php-snippetsfrom
fix-php-snippets

Conversation

@mnocon

@mnocon mnocon commented May 17, 2026

Copy link
Copy Markdown
Contributor

This PR fixes the existing inlined PHP code samples, using the following tools:

  • PHPStan
  • Rector
  • CS-Fixer
  • Deptrac

To avoid triggering the PHPStan baselined error every time the Markdown content around a code sample changes, the line-numbered files are renamed to use sha-256 as the filename.
This way, PHPStan correctly remembers the checked file even if the content around (and thus, line numbers) change.

@github-actions

github-actions Bot commented May 17, 2026

Copy link
Copy Markdown

Preview of modified files: Too many files modified in a single PR, preview link list is skipped. (295 files > 150)

@sonarqubecloud

Copy link
Copy Markdown

```php
use Symfony\Component\HttpFoundation\Request;

/** @var \Symfony\Component\HttpFoundation\Request $request */

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@ibexa/php-dev @vidarl @reithor could you please help me and confirm that this change is ok?

Request::HEADER_X_FORWARDED_ALL is removed in Symfony 6/7, I found this:

https://github.com/symfony/symfony/blame/b01d14a27dcd5ca91c5af11ca3cb41ffbe639de7/src/Symfony/Component/HttpFoundation/CHANGELOG.md#L128

I'm sure about other changes in this PR, but for this one would like a confirmation

@mnocon mnocon marked this pull request as ready for review June 23, 2026 07:55
@mnocon mnocon force-pushed the test-php-snippets branch 6 times, most recently from 02b34ef to c72a5c4 Compare June 23, 2026 14:05
@mnocon mnocon force-pushed the fix-php-snippets branch from 24aad10 to db52c22 Compare June 23, 2026 14:18
@mnocon mnocon force-pushed the fix-php-snippets branch from db52c22 to 182451d Compare June 23, 2026 14:32
@github-actions

Copy link
Copy Markdown

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/api/public_php_api/src/Command/SegmentCommand.php

docs/users/segment_api.md@17:``` php
docs/users/segment_api.md@18:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 49, 55, remove_indent=True) =]]
docs/users/segment_api.md@19:```

001⫶$segmentGroup = $this->segmentationService->loadSegmentGroupByIdentifier('custom_group');
002⫶
003⫶$segments = $this->segmentationService->loadSegmentsAssignedToGroup($segmentGroup);
004⫶
005⫶foreach ($segments as $segment) {
006⫶ $output->writeln('Segment identifier: ' . $segment->getIdentifier() . ', name: ' . $segment->getName());
007⫶}

docs/users/segment_api.md@23:``` php
docs/users/segment_api.md@24:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 57, 57, remove_indent=True) =]]
docs/users/segment_api.md@25:```

001⫶$segment = $this->segmentationService->loadSegmentByIdentifier('segment_1');

docs/users/segment_api.md@31:``` php
docs/users/segment_api.md@32:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 61, 65, remove_indent=True) =]]
docs/users/segment_api.md@33:```

001⫶$output->writeln((
002⫶ $this->segmentationService->isUserAssignedToSegment($user, $segment)
003⫶ ? 'The user is assigned to the segment.'
004⫶ : 'The user is not assigned to the segment.'
005⫶));

docs/users/segment_api.md@39:``` php
docs/users/segment_api.md@40:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 59, 59, remove_indent=True) =]]
docs/users/segment_api.md@41:```

001⫶$this->segmentationService->assignUserToSegment($user, $segment);

docs/users/segment_api.md@49:``` php
docs/users/segment_api.md@50:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 33, 39, remove_indent=True) =]]
docs/users/segment_api.md@51:```

001⫶$segmentGroupCreateStruct = new SegmentGroupCreateStruct([
002⫶ 'name' => 'Custom Group',
003⫶ 'identifier' => 'custom_group',
004⫶ 'createSegments' => [],
005⫶]);
006⫶
007⫶$newSegmentGroup = $this->segmentationService->createSegmentGroup($segmentGroupCreateStruct);

docs/users/segment_api.md@55:``` php
docs/users/segment_api.md@56:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 41, 47, remove_indent=True) =]]
docs/users/segment_api.md@57:```

001⫶$segmentCreateStruct = new SegmentCreateStruct([
002⫶ 'name' => 'Segment 1',
003⫶ 'identifier' => 'segment_1',
004⫶ 'group' => $newSegmentGroup,
005⫶]);
006⫶
007⫶$newSegment = $this->segmentationService->createSegment($segmentCreateStruct);


code_samples/api/public_php_api/src/Command/SegmentCommand.php

docs/users/segment_api.md@17:``` php
docs/users/segment_api.md@18:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 49, 55, remove_indent=True) =]]
docs/users/segment_api.md@19:```

001⫶$segmentGroup = $this->segmentationService->loadSegmentGroupByIdentifier('custom_group');
002⫶
003⫶$segments = $this->segmentationService->loadSegmentsAssignedToGroup($segmentGroup);
004⫶
005⫶foreach ($segments as $segment) {
006⫶ $output->writeln('Segment identifier: ' . $segment->getIdentifier() . ', name: ' . $segment->getName());
007⫶}

docs/users/segment_api.md@23:``` php
docs/users/segment_api.md@24:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 57, 57, remove_indent=True) =]]
docs/users/segment_api.md@25:```

001⫶$segment = $this->segmentationService->loadSegmentByIdentifier('segment_1');

docs/users/segment_api.md@31:``` php
docs/users/segment_api.md@32:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 61, 65, remove_indent=True) =]]
docs/users/segment_api.md@33:```

001⫶$output->writeln((
002⫶ $this->segmentationService->isUserAssignedToSegment($user, $segment)
003⫶ ? 'The user is assigned to the segment.'
004⫶ : 'The user is not assigned to the segment.'
005⫶));

docs/users/segment_api.md@39:``` php
docs/users/segment_api.md@40:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 59, 59, remove_indent=True) =]]
docs/users/segment_api.md@41:```

001⫶$this->segmentationService->assignUserToSegment($user, $segment);

docs/users/segment_api.md@49:``` php
docs/users/segment_api.md@50:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 33, 39, remove_indent=True) =]]
docs/users/segment_api.md@51:```

001⫶$segmentGroupCreateStruct = new SegmentGroupCreateStruct([
002⫶ 'name' => 'Custom Group',
003⫶ 'identifier' => 'custom_group',
004⫶ 'createSegments' => [],
005⫶]);
006⫶
007⫶$newSegmentGroup = $this->segmentationService->createSegmentGroup($segmentGroupCreateStruct);

docs/users/segment_api.md@55:``` php
docs/users/segment_api.md@56:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 41, 47, remove_indent=True) =]]
docs/users/segment_api.md@57:```

001⫶$segmentCreateStruct = new SegmentCreateStruct([
002⫶ 'name' => 'Segment 1',
003⫶ 'identifier' => 'segment_1',
004⫶ 'group' => $newSegmentGroup,
005⫶]);
006⫶
007⫶$newSegment = $this->segmentationService->createSegment($segmentCreateStruct);

docs/users/segment_api.md@67:``` php
docs/users/segment_api.md@68:[[= include_code('code_samples/api/public_php_api/src/Command/SegmentCommand.php', 67, 67, remove_indent=True) =]]
docs/users/segment_api.md@69:```

001⫶$this->segmentationService->removeSegmentGroup($segmentGroup);

Download colorized diff

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.

1 participant