Skip to content

Commit

Permalink
[Coding Style] Enable rule PSR2.Classes.PropertyDeclaration.Underscore (
Browse files Browse the repository at this point in the history
#22140)

* [Coding Style] Enable rule PSR2.Classes.PropertyDeclaration.Underscore
* Apply CS
* Fix tests
  • Loading branch information
sgiehl committed Apr 22, 2024
1 parent 9a3ef94 commit 691dd60
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 109 deletions.
2 changes: 1 addition & 1 deletion core/EventDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static function getInstance()

private $pluginHooks = array();

public static $_SKIP_EVENTS_IN_TESTS = false;
public static $_SKIP_EVENTS_IN_TESTS = false; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore

/**
* Constructor.
Expand Down
16 changes: 8 additions & 8 deletions core/Visualization/Sparkline.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ class Sparkline implements ViewInterface
* Width of the sparkline
* @var int
*/
protected $_width = self::DEFAULT_WIDTH;
protected $width = self::DEFAULT_WIDTH;
/**
* Height of sparkline
* @var int
*/
protected $_height = self::DEFAULT_HEIGHT;
protected $height = self::DEFAULT_HEIGHT;
private $serieses = [];
/**
* @var \Davaxi\Sparkline
Expand Down Expand Up @@ -120,7 +120,7 @@ public function main()
*/
public function getWidth()
{
return $this->_width;
return $this->width;
}

/**
Expand All @@ -133,9 +133,9 @@ public function setWidth($width)
return;
}
if ($width > self::MAX_WIDTH) {
$this->_width = self::MAX_WIDTH;
$this->width = self::MAX_WIDTH;
} else {
$this->_width = (int)$width;
$this->width = (int)$width;
}
}

Expand All @@ -145,7 +145,7 @@ public function setWidth($width)
*/
public function getHeight()
{
return $this->_height;
return $this->height;
}

/**
Expand All @@ -158,9 +158,9 @@ public function setHeight($height)
return;
}
if ($height > self::MAX_HEIGHT) {
$this->_height = self::MAX_HEIGHT;
$this->height = self::MAX_HEIGHT;
} else {
$this->_height = (int)$height;
$this->height = (int)$height;
}
}

Expand Down
1 change: 0 additions & 1 deletion phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

<exclude name="Generic.Files.LineLength" />
<exclude name="Generic.PHP.LowerCaseConstant.Found" />
<exclude name="PSR2.Classes.PropertyDeclaration.Underscore" />
</rule>

<rule ref="Squiz.Classes.ValidClassName.NotCamelCaps">
Expand Down
2 changes: 1 addition & 1 deletion plugins/API/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class API extends \Piwik\Plugin\API
* For Testing purpose only
* @var int
*/
public static $_autoSuggestLookBack = 60;
public static $_autoSuggestLookBack = 60; // phpcs:ignore PSR2.Classes.PropertyDeclaration.Underscore

public function __construct(SettingsProvider $settingsProvider, ProcessedReport $processedReport)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function test_check_shouldOnlyReturnTrue_IfAdShouldBeShown(bool $adsForPr
$this->assertEquals($expected, $sut->check('MyPlugin', 'Any'));
}

protected function checkDataProvider(): \Generator
public function checkDataProvider(): \Generator
{
yield [true, true, true, true, false, false];
yield [true, true, true, false, false, true];
Expand Down
40 changes: 20 additions & 20 deletions tests/PHPUnit/Unit/Scheduler/Schedule/DailyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@
*/
class DailyTest extends \PHPUnit\Framework\TestCase
{
private static $_JANUARY_01_1971_09_00_00;
private static $_JANUARY_01_1971_09_10_00;
private static $_JANUARY_01_1971_12_10_00;
private static $_JANUARY_02_1971_00_00_00;
private static $_JANUARY_02_1971_09_00_00;
private static $JANUARY_01_1971_09_00_00;
private static $JANUARY_01_1971_09_10_00;
private static $JANUARY_01_1971_12_10_00;
private static $JANUARY_02_1971_00_00_00;
private static $JANUARY_02_1971_09_00_00;

public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::$_JANUARY_01_1971_09_00_00 = mktime(9, 00, 00, 1, 1, 1971);
self::$_JANUARY_01_1971_09_10_00 = mktime(9, 10, 00, 1, 1, 1971);
self::$_JANUARY_01_1971_12_10_00 = mktime(12, 10, 00, 1, 1, 1971);
self::$_JANUARY_02_1971_00_00_00 = mktime(0, 00, 00, 1, 2, 1971);
self::$_JANUARY_02_1971_09_00_00 = mktime(9, 00, 00, 1, 2, 1971);
self::$JANUARY_01_1971_09_00_00 = mktime(9, 00, 00, 1, 1, 1971);
self::$JANUARY_01_1971_09_10_00 = mktime(9, 10, 00, 1, 1, 1971);
self::$JANUARY_01_1971_12_10_00 = mktime(12, 10, 00, 1, 1, 1971);
self::$JANUARY_02_1971_00_00_00 = mktime(0, 00, 00, 1, 2, 1971);
self::$JANUARY_02_1971_09_00_00 = mktime(9, 00, 00, 1, 2, 1971);
}

/**
Expand Down Expand Up @@ -82,17 +82,17 @@ public function testGetRescheduledTimeDailyUnspecifiedHour()
* Expected :
* getRescheduledTime returns Saturday January 2 1971 00:00:00 UTC
*/
$mock = $this->getDailyMock(self::$_JANUARY_01_1971_09_10_00);
$this->assertEquals(self::$_JANUARY_02_1971_00_00_00, $mock->getRescheduledTime());
$mock = $this->getDailyMock(self::$JANUARY_01_1971_09_10_00);
$this->assertEquals(self::$JANUARY_02_1971_00_00_00, $mock->getRescheduledTime());
}

public function test_setTimezone_ShouldConvertRescheduledTime()
{
$oneHourInSeconds = 3600;

$mock = $this->getDailyMock(self::$_JANUARY_01_1971_09_10_00);
$mock = $this->getDailyMock(self::$JANUARY_01_1971_09_10_00);
$timeUTC = $mock->getRescheduledTime();
$this->assertEquals(self::$_JANUARY_02_1971_00_00_00, $timeUTC);
$this->assertEquals(self::$JANUARY_02_1971_00_00_00, $timeUTC);

$mock->setTimezone('Pacific/Auckland');
$timeAuckland = $mock->getRescheduledTime();
Expand All @@ -118,9 +118,9 @@ public function testGetRescheduledTimeDailySpecifiedHour()
* Expected :
* getRescheduledTime returns Saturday January 2 1971 09:00:00 UTC
*/
$mock = $this->getDailyMock(self::$_JANUARY_01_1971_09_00_00);
$mock = $this->getDailyMock(self::$JANUARY_01_1971_09_00_00);
$mock->setHour(9);
$this->assertEquals(self::$_JANUARY_02_1971_09_00_00, $mock->getRescheduledTime());
$this->assertEquals(self::$JANUARY_02_1971_09_00_00, $mock->getRescheduledTime());

/*
* Test 2
Expand All @@ -133,9 +133,9 @@ public function testGetRescheduledTimeDailySpecifiedHour()
* getRescheduledTime returns Saturday January 2 1971 09:00:00 UTC
*/

$mock = $this->getDailyMock(self::$_JANUARY_01_1971_12_10_00);
$mock = $this->getDailyMock(self::$JANUARY_01_1971_12_10_00);
$mock->setHour(9);
$this->assertEquals(self::$_JANUARY_02_1971_09_00_00, $mock->getRescheduledTime());
$this->assertEquals(self::$JANUARY_02_1971_09_00_00, $mock->getRescheduledTime());

/*
* Test 3
Expand All @@ -147,9 +147,9 @@ public function testGetRescheduledTimeDailySpecifiedHour()
* Expected :
* getRescheduledTime returns Saturday January 2 1971 00:00:00 UTC
*/
$mock = $this->getDailyMock(self::$_JANUARY_01_1971_12_10_00);
$mock = $this->getDailyMock(self::$JANUARY_01_1971_12_10_00);
$mock->setHour(0);
$this->assertEquals(self::$_JANUARY_02_1971_00_00_00, $mock->getRescheduledTime());
$this->assertEquals(self::$JANUARY_02_1971_00_00_00, $mock->getRescheduledTime());
}

/**
Expand Down
20 changes: 10 additions & 10 deletions tests/PHPUnit/Unit/Scheduler/Schedule/HourlyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
*/
class HourlyTest extends \PHPUnit\Framework\TestCase
{
private static $_JANUARY_01_1971_09_00_00;
private static $_JANUARY_01_1971_09_10_00;
private static $_JANUARY_01_1971_10_00_00;
private static $JANUARY_01_1971_09_00_00;
private static $JANUARY_01_1971_09_10_00;
private static $JANUARY_01_1971_10_00_00;

public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
self::$_JANUARY_01_1971_09_00_00 = mktime(9, 00, 00, 1, 1, 1971);
self::$_JANUARY_01_1971_09_10_00 = mktime(9, 10, 00, 1, 1, 1971);
self::$_JANUARY_01_1971_10_00_00 = mktime(10, 00, 00, 1, 1, 1971);
self::$JANUARY_01_1971_09_00_00 = mktime(9, 00, 00, 1, 1, 1971);
self::$JANUARY_01_1971_09_10_00 = mktime(9, 10, 00, 1, 1, 1971);
self::$JANUARY_01_1971_10_00_00 = mktime(10, 00, 00, 1, 1, 1971);
}

/**
Expand Down Expand Up @@ -71,8 +71,8 @@ public function testGetRescheduledTimeHourly()
$mock = $this->createPartialMock('Piwik\Scheduler\Schedule\Hourly', array('getTime'));
$mock->expects($this->any())
->method('getTime')
->will($this->returnValue(self::$_JANUARY_01_1971_09_00_00));
$this->assertEquals(self::$_JANUARY_01_1971_10_00_00, $mock->getRescheduledTime());
->will($this->returnValue(self::$JANUARY_01_1971_09_00_00));
$this->assertEquals(self::$JANUARY_01_1971_10_00_00, $mock->getRescheduledTime());

/*
* Test 2
Expand All @@ -86,7 +86,7 @@ public function testGetRescheduledTimeHourly()
$mock = $this->createPartialMock('Piwik\Scheduler\Schedule\Hourly', array('getTime'));
$mock->expects($this->any())
->method('getTime')
->will($this->returnValue(self::$_JANUARY_01_1971_09_10_00));
$this->assertEquals(self::$_JANUARY_01_1971_10_00_00, $mock->getRescheduledTime());
->will($this->returnValue(self::$JANUARY_01_1971_09_10_00));
$this->assertEquals(self::$JANUARY_01_1971_10_00_00, $mock->getRescheduledTime());
}
}
Loading

0 comments on commit 691dd60

Please sign in to comment.