Skip to content

Commit 466e040

Browse files
committed
Sniff: add getter for the standard, category and sniff name
Includes tests.
1 parent 806997b commit 466e040

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

src/Value/Sniff.php

+26
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
class Sniff
99
{
1010
private string $code;
11+
private string $standardName;
12+
private string $categoryName;
13+
private string $sniffName;
1114
private string $docblock;
1215
/**
1316
* @var Property[]
@@ -42,6 +45,11 @@ public function __construct(
4245
Assert::that($code)
4346
->notBlank();
4447

48+
$sniffNameParts = explode('.', $code);
49+
Assert::that($sniffNameParts)
50+
->isArray()
51+
->count(3);
52+
4553
Assert::thatAll($properties)
4654
->isInstanceOf(Property::class);
4755

@@ -52,6 +60,9 @@ public function __construct(
5260
->isInstanceOf(Violation::class);
5361

5462
$this->code = $code;
63+
$this->standardName = $sniffNameParts[0];
64+
$this->categoryName = $sniffNameParts[1];
65+
$this->sniffName = $sniffNameParts[2];
5566
$this->docblock = $docblock;
5667
$this->properties = array_values($properties);
5768
$this->urls = $urls;
@@ -65,6 +76,21 @@ public function getCode(): string
6576
return $this->code;
6677
}
6778

79+
public function getStandardName(): string
80+
{
81+
return $this->standardName;
82+
}
83+
84+
public function getCategoryName(): string
85+
{
86+
return $this->categoryName;
87+
}
88+
89+
public function getSniffName(): string
90+
{
91+
return $this->sniffName;
92+
}
93+
6894
public function getDocblock(): string
6995
{
7096
return $this->docblock;

tests/Value/SniffTest.php

+30
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
class SniffTest extends TestCase
1717
{
1818
const CODE = 'Standard.Category.Code';
19+
const STANDARD = 'Standard';
20+
const CATEGORY = 'Category';
21+
const SNIFFNAME = 'Code';
1922
const DOCBLOCK = 'Docblock';
2023
const DESCRIPTION = 'Description';
2124
/**
@@ -128,6 +131,33 @@ public function getCode()
128131
);
129132
}
130133

134+
/** @test */
135+
public function getStandardName()
136+
{
137+
self::assertSame(
138+
self::STANDARD,
139+
$this->createSniff()->getStandardName()
140+
);
141+
}
142+
143+
/** @test */
144+
public function getCategoryName()
145+
{
146+
self::assertSame(
147+
self::CATEGORY,
148+
$this->createSniff()->getCategoryName()
149+
);
150+
}
151+
152+
/** @test */
153+
public function getSniffName()
154+
{
155+
self::assertSame(
156+
self::SNIFFNAME,
157+
$this->createSniff()->getSniffName()
158+
);
159+
}
160+
131161
protected function setUp(): void
132162
{
133163
$this->PROPERTIES = [

0 commit comments

Comments
 (0)