Skip to content

Commit cc42ff7

Browse files
committed
Merge branch 'develop'
* develop: New rule: No Typographic Quotes (#2011) Enhancement: Update dependencies in `composer.json` (#2010) Enhancement: Update dependencies in `composer.json` (#2009) Enhancement: Update dependencies in `composer.json` (#2008) Enhancement: Update dependencies in `composer.json` (#2007) composer(deps-dev): bump rector/rector from 2.0.15 to 2.0.16 (#2006) composer(deps-dev): bump phpunit/phpunit from 12.1.4 to 12.1.5 (#2005) composer(deps-dev): bump icanhazstring/composer-unused from 0.9.2 to 0.9.3 (#2004)
2 parents ce90869 + f63cd7e commit cc42ff7

File tree

5 files changed

+200
-43
lines changed

5 files changed

+200
-43
lines changed

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@
2424
"ergebnis/data-provider": "^3.4",
2525
"ergebnis/php-cs-fixer-config": "^6.46.0",
2626
"friendsofphp/php-cs-fixer": "^3.75.0",
27-
"icanhazstring/composer-unused": "^0.9.2",
27+
"icanhazstring/composer-unused": "^0.9.3",
2828
"maglnet/composer-require-checker": "^4.16.1",
2929
"mikey179/vfsstream": "^1.6.12",
3030
"phpstan/extension-installer": "^1.4.3",
31-
"phpstan/phpstan": "^2.1.14",
31+
"phpstan/phpstan": "^2.1.15",
3232
"phpstan/phpstan-phpunit": "^2.0.6",
3333
"phpstan/phpstan-webmozart-assert": "^2.0.0",
34-
"phpunit/phpunit": "^12.1.4",
35-
"rector/rector": "^2.0.15",
34+
"phpunit/phpunit": "^12.1.5",
35+
"rector/rector": "^2.0.16",
3636
"symfony/var-dumper": "^7.2.6"
3737
},
3838
"replace": {

composer.lock

Lines changed: 39 additions & 39 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/rules.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
* [no_php_prefix_before_bin_console](#no_php_prefix_before_bin_console)
7373
* [no_php_prefix_before_composer](#no_php_prefix_before_composer)
7474
* [no_space_before_self_xml_closing_tag](#no_space_before_self_xml_closing_tag)
75+
* [no_typographic_quotes](#no_typographic_quotes)
7576
* [non_static_phpunit_assertions](#non_static_phpunit_assertions)
7677
* [only_backslashes_in_namespace_in_php_code_block](#only_backslashes_in_namespace_in_php_code_block)
7778
* [only_backslashes_in_use_statements_in_php_code_block](#only_backslashes_in_use_statements_in_php_code_block)
@@ -846,6 +847,24 @@ php bin/console list
846847

847848
#### Groups [`@Sonata`]
848849

850+
## `no_typographic_quotes`
851+
852+
> _Do not use typographic quotes._
853+
854+
#### Groups [`@Symfony`]
855+
856+
##### Valid Examples :+1:
857+
858+
```rst
859+
Lorem 'ipsum' dolor "sit amet"
860+
```
861+
862+
##### Invalid Examples :-1:
863+
864+
```rst
865+
Lorem ‘ipsum’ dolor “sit amet”
866+
```
867+
849868
## `non_static_phpunit_assertions`
850869

851870
> _Use `$this->assert*` over static calls._

src/Rule/NoTypographicQuotes.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* This file is part of DOCtor-RST.
7+
*
8+
* (c) Oskar Stark <[email protected]>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace App\Rule;
15+
16+
use App\Attribute\Rule\Description;
17+
use App\Attribute\Rule\InvalidExample;
18+
use App\Attribute\Rule\ValidExample;
19+
use App\Value\Lines;
20+
use App\Value\NullViolation;
21+
use App\Value\RuleGroup;
22+
use App\Value\Violation;
23+
use App\Value\ViolationInterface;
24+
25+
#[Description('Do not use typographic quotes.')]
26+
#[ValidExample('Lorem \'ipsum\' dolor "sit amet"')]
27+
#[InvalidExample('Lorem ‘ipsum’ dolor “sit amet”')]
28+
final class NoTypographicQuotes extends AbstractRule implements LineContentRule
29+
{
30+
public static function getGroups(): array
31+
{
32+
return [RuleGroup::Symfony()];
33+
}
34+
35+
public function check(Lines $lines, int $number, string $filename): ViolationInterface
36+
{
37+
$lines->seek($number);
38+
$line = $lines->current();
39+
40+
$lineContent = $line->raw();
41+
if ($lineContent->containsAny(['', ''])) {
42+
return Violation::from(
43+
'Please use straight single quotes (\' ... \') instead of curly quotes (‘ ... ’)',
44+
$filename,
45+
$number + 1,
46+
$line,
47+
);
48+
}
49+
50+
if ($lineContent->containsAny(['', '', '', '', '«', '»'])) {
51+
return Violation::from(
52+
'Please use straight double quotes (" ... ") instead of curly quotes (“ ... ”)',
53+
$filename,
54+
$number + 1,
55+
$line,
56+
);
57+
}
58+
59+
return NullViolation::create();
60+
}
61+
}

0 commit comments

Comments
 (0)