Avoid `call_user_func()` whenever possible

This commit is contained in:
Adrien Crivelli 2016-08-26 15:39:29 +09:00
parent 04d6182a81
commit f917b3b1f4
No known key found for this signature in database
GPG Key ID: B182FD79DC6DE92E
11 changed files with 49 additions and 70 deletions

View File

@ -323,9 +323,9 @@ class TextDataTest extends \PHPUnit_Framework_TestCase
public function testTEXT()
{
// Enforce decimal and thousands separator values to UK/US, and currency code to USD
call_user_func([StringHelper::class, 'setDecimalSeparator'], '.');
call_user_func([StringHelper::class, 'setThousandsSeparator'], ',');
call_user_func([StringHelper::class, 'setCurrencyCode'], '$');
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(',');
StringHelper::setCurrencyCode('$');
$args = func_get_args();
$expectedResult = array_pop($args);
@ -343,9 +343,9 @@ class TextDataTest extends \PHPUnit_Framework_TestCase
*/
public function testVALUE()
{
call_user_func([StringHelper::class, 'setDecimalSeparator'], '.');
call_user_func([StringHelper::class, 'setThousandsSeparator'], ' ');
call_user_func([StringHelper::class, 'setCurrencyCode'], '$');
StringHelper::setDecimalSeparator('.');
StringHelper::setThousandsSeparator(' ');
StringHelper::setCurrencyCode('$');
$args = func_get_args();
$expectedResult = array_pop($args);

View File

@ -16,7 +16,7 @@ class DataTypeTest extends \PHPUnit_Framework_TestCase
public function testGetErrorCodes()
{
$result = call_user_func([DataType::class, 'getErrorCodes']);
$result = DataType::getErrorCodes();
$this->assertInternalType('array', $result);
$this->assertGreaterThan(0, count($result));
$this->assertArrayHasKey('#NULL!', $result);

View File

@ -81,7 +81,7 @@ class DefaultValueBinderTest extends \PHPUnit_Framework_TestCase
$objRichText->createText('Hello World');
$expectedResult = DataType::TYPE_INLINE;
$result = call_user_func([DefaultValueBinder::class, 'dataTypeForValue'], $objRichText);
$result = DefaultValueBinder::dataTypeForValue($objRichText);
$this->assertEquals($expectedResult, $result);
}
}

View File

@ -27,7 +27,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
{
$cellAddress = 'ABCD';
try {
call_user_func([Cell::class, 'columnIndexFromString'], $cellAddress);
Cell::columnIndexFromString($cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals($e->getMessage(), 'Column string index can not be longer than 3 characters');
@ -41,7 +41,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
{
$cellAddress = '';
try {
call_user_func([Cell::class, 'columnIndexFromString'], $cellAddress);
Cell::columnIndexFromString($cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals($e->getMessage(), 'Column string index can not be empty');
@ -87,7 +87,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
{
$cellAddress = 'A1:AI2012';
try {
call_user_func([Cell::class, 'coordinateFromString'], $cellAddress);
Cell::coordinateFromString($cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
@ -101,7 +101,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
{
$cellAddress = '';
try {
call_user_func([Cell::class, 'coordinateFromString'], $cellAddress);
Cell::coordinateFromString($cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals($e->getMessage(), 'Cell coordinate can not be zero-length string');
@ -115,7 +115,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
{
$cellAddress = 'AI';
try {
call_user_func([Cell::class, 'coordinateFromString'], $cellAddress);
Cell::coordinateFromString($cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals($e->getMessage(), 'Invalid cell coordinate ' . $cellAddress);
@ -145,7 +145,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
{
$cellAddress = 'A1:AI2012';
try {
call_user_func([Cell::class, 'absoluteCoordinate'], $cellAddress);
Cell::absoluteCoordinate($cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
@ -175,7 +175,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
{
$cellAddress = 'A1:AI2012';
try {
call_user_func([Cell::class, 'absoluteReference'], $cellAddress);
Cell::absoluteReference($cellAddress);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals($e->getMessage(), 'Cell coordinate string can not be a range of cells');
@ -227,7 +227,7 @@ class CellTest extends \PHPUnit_Framework_TestCase
{
$cellRange = '';
try {
call_user_func([Cell::class, 'buildRange'], $cellRange);
Cell::buildRange($cellRange);
} catch (\Exception $e) {
$this->assertInstanceOf(Exception::class, $e);
$this->assertEquals($e->getMessage(), 'Range does not contain any information');

View File

@ -12,7 +12,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
*/
public function testGetXMLSettings()
{
$result = call_user_func([\PhpSpreadsheet\Settings::class, 'getLibXmlLoaderOptions']);
$result = \PhpSpreadsheet\Settings::getLibXmlLoaderOptions();
$this->assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR) & $result));
}
@ -21,7 +21,7 @@ class SettingsTest extends \PHPUnit_Framework_TestCase
public function testSetXMLSettings()
{
call_user_func_array([\PhpSpreadsheet\Settings::class, 'setLibXmlLoaderOptions'], [LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID]);
$result = call_user_func([\PhpSpreadsheet\Settings::class, 'getLibXmlLoaderOptions']);
$result = \PhpSpreadsheet\Settings::getLibXmlLoaderOptions();
$this->assertTrue((bool) ((LIBXML_DTDLOAD | LIBXML_DTDATTR | LIBXML_DTDVALID) & $result));
}
}

View File

@ -27,7 +27,7 @@ class CodePageTest extends \PHPUnit_Framework_TestCase
{
$invalidCodePage = 12345;
try {
call_user_func([CodePage::class, 'numberToName'], $invalidCodePage);
CodePage::numberToName($invalidCodePage);
} catch (Exception $e) {
$this->assertEquals($e->getMessage(), 'Unknown codepage: 12345');
@ -40,7 +40,7 @@ class CodePageTest extends \PHPUnit_Framework_TestCase
{
$unsupportedCodePage = 720;
try {
call_user_func([CodePage::class, 'numberToName'], $unsupportedCodePage);
CodePage::numberToName($unsupportedCodePage);
} catch (Exception $e) {
$this->assertEquals($e->getMessage(), 'Code page 720 not supported.');

View File

@ -14,7 +14,7 @@ class DateTest extends \PHPUnit_Framework_TestCase
];
foreach ($calendarValues as $calendarValue) {
$result = call_user_func([Date::class, 'setExcelCalendar'], $calendarValue);
$result = Date::setExcelCalendar($calendarValue);
$this->assertTrue($result);
}
}
@ -22,7 +22,7 @@ class DateTest extends \PHPUnit_Framework_TestCase
public function testSetExcelCalendarWithInvalidValue()
{
$unsupportedCalendar = '2012';
$result = call_user_func([Date::class, 'setExcelCalendar'], $unsupportedCalendar);
$result = Date::setExcelCalendar($unsupportedCalendar);
$this->assertFalse($result);
}
@ -31,10 +31,7 @@ class DateTest extends \PHPUnit_Framework_TestCase
*/
public function testDateTimeExcelToTimestamp1900()
{
call_user_func(
[Date::class, 'setExcelCalendar'],
Date::CALENDAR_WINDOWS_1900
);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
$args = func_get_args();
$expectedResult = array_pop($args);
@ -52,10 +49,7 @@ class DateTest extends \PHPUnit_Framework_TestCase
*/
public function testDateTimeTimestampToExcel1900()
{
call_user_func(
[Date::class, 'setExcelCalendar'],
Date::CALENDAR_WINDOWS_1900
);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
$args = func_get_args();
$expectedResult = array_pop($args);
@ -73,10 +67,7 @@ class DateTest extends \PHPUnit_Framework_TestCase
*/
public function testDateTimeDateTimeToExcel()
{
call_user_func(
[Date::class, 'setExcelCalendar'],
Date::CALENDAR_WINDOWS_1900
);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
$args = func_get_args();
$expectedResult = array_pop($args);
@ -94,10 +85,7 @@ class DateTest extends \PHPUnit_Framework_TestCase
*/
public function testDateTimeFormattedPHPToExcel1900()
{
call_user_func(
[Date::class, 'setExcelCalendar'],
Date::CALENDAR_WINDOWS_1900
);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
$args = func_get_args();
$expectedResult = array_pop($args);
@ -115,10 +103,7 @@ class DateTest extends \PHPUnit_Framework_TestCase
*/
public function testDateTimeExcelToTimestamp1904()
{
call_user_func(
[Date::class, 'setExcelCalendar'],
Date::CALENDAR_MAC_1904
);
Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
$args = func_get_args();
$expectedResult = array_pop($args);
@ -136,10 +121,7 @@ class DateTest extends \PHPUnit_Framework_TestCase
*/
public function testDateTimeTimestampToExcel1904()
{
call_user_func(
[Date::class, 'setExcelCalendar'],
Date::CALENDAR_MAC_1904
);
Date::setExcelCalendar(Date::CALENDAR_MAC_1904);
$args = func_get_args();
$expectedResult = array_pop($args);
@ -173,10 +155,7 @@ class DateTest extends \PHPUnit_Framework_TestCase
*/
public function testDateTimeExcelToTimestamp1900Timezone()
{
call_user_func(
[Date::class, 'setExcelCalendar'],
Date::CALENDAR_WINDOWS_1900
);
Date::setExcelCalendar(Date::CALENDAR_WINDOWS_1900);
$args = func_get_args();
$expectedResult = array_pop($args);

View File

@ -10,7 +10,7 @@ class FileTest extends \PHPUnit_Framework_TestCase
{
$expectedResult = false;
$result = call_user_func([File::class, 'getUseUploadTempDirectory']);
$result = File::getUseUploadTempDirectory();
$this->assertEquals($expectedResult, $result);
}
@ -22,9 +22,9 @@ class FileTest extends \PHPUnit_Framework_TestCase
];
foreach ($useUploadTempDirectoryValues as $useUploadTempDirectoryValue) {
call_user_func([File::class, 'setUseUploadTempDirectory'], $useUploadTempDirectoryValue);
File::setUseUploadTempDirectory($useUploadTempDirectoryValue);
$result = call_user_func([File::class, 'getUseUploadTempDirectory']);
$result = File::getUseUploadTempDirectory();
$this->assertEquals($useUploadTempDirectoryValue, $result);
}
}

View File

@ -10,7 +10,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
{
$expectedResult = Font::AUTOSIZE_METHOD_APPROX;
$result = call_user_func([Font::class, 'getAutoSizeMethod']);
$result = Font::getAutoSizeMethod();
$this->assertEquals($expectedResult, $result);
}
@ -22,7 +22,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
];
foreach ($autosizeMethodValues as $autosizeMethodValue) {
$result = call_user_func([Font::class, 'setAutoSizeMethod'], $autosizeMethodValue);
$result = Font::setAutoSizeMethod($autosizeMethodValue);
$this->assertTrue($result);
}
}
@ -31,7 +31,7 @@ class FontTest extends \PHPUnit_Framework_TestCase
{
$unsupportedAutosizeMethod = 'guess';
$result = call_user_func([Font::class, 'setAutoSizeMethod'], $unsupportedAutosizeMethod);
$result = Font::setAutoSizeMethod($unsupportedAutosizeMethod);
$this->assertFalse($result);
}

View File

@ -11,18 +11,18 @@ class StringTest extends \PHPUnit_Framework_TestCase
parent::setUp();
// Reset Currency Code
call_user_func([StringHelper::class, 'setCurrencyCode'], null);
StringHelper::setCurrencyCode(null);
}
public function testGetIsMbStringEnabled()
{
$result = call_user_func([StringHelper::class, 'getIsMbstringEnabled']);
$result = StringHelper::getIsMbstringEnabled();
$this->assertTrue($result);
}
public function testGetIsIconvEnabled()
{
$result = call_user_func([StringHelper::class, 'getIsIconvEnabled']);
$result = StringHelper::getIsIconvEnabled();
$this->assertTrue($result);
}
@ -31,16 +31,16 @@ class StringTest extends \PHPUnit_Framework_TestCase
$localeconv = localeconv();
$expectedResult = (!empty($localeconv['decimal_point'])) ? $localeconv['decimal_point'] : ',';
$result = call_user_func([StringHelper::class, 'getDecimalSeparator']);
$result = StringHelper::getDecimalSeparator();
$this->assertEquals($expectedResult, $result);
}
public function testSetDecimalSeparator()
{
$expectedResult = ',';
call_user_func([StringHelper::class, 'setDecimalSeparator'], $expectedResult);
StringHelper::setDecimalSeparator($expectedResult);
$result = call_user_func([StringHelper::class, 'getDecimalSeparator']);
$result = StringHelper::getDecimalSeparator();
$this->assertEquals($expectedResult, $result);
}
@ -49,16 +49,16 @@ class StringTest extends \PHPUnit_Framework_TestCase
$localeconv = localeconv();
$expectedResult = (!empty($localeconv['thousands_sep'])) ? $localeconv['thousands_sep'] : ',';
$result = call_user_func([StringHelper::class, 'getThousandsSeparator']);
$result = StringHelper::getThousandsSeparator();
$this->assertEquals($expectedResult, $result);
}
public function testSetThousandsSeparator()
{
$expectedResult = ' ';
call_user_func([StringHelper::class, 'setThousandsSeparator'], $expectedResult);
StringHelper::setThousandsSeparator($expectedResult);
$result = call_user_func([StringHelper::class, 'getThousandsSeparator']);
$result = StringHelper::getThousandsSeparator();
$this->assertEquals($expectedResult, $result);
}
@ -66,16 +66,16 @@ class StringTest extends \PHPUnit_Framework_TestCase
{
$localeconv = localeconv();
$expectedResult = (!empty($localeconv['currency_symbol']) ? $localeconv['currency_symbol'] : (!empty($localeconv['int_curr_symbol']) ? $localeconv['int_curr_symbol']: '$'));
$result = call_user_func([StringHelper::class, 'getCurrencyCode']);
$result = StringHelper::getCurrencyCode();
$this->assertEquals($expectedResult, $result);
}
public function testSetCurrencyCode()
{
$expectedResult = '£';
call_user_func([StringHelper::class, 'setCurrencyCode'], $expectedResult);
StringHelper::setCurrencyCode($expectedResult);
$result = call_user_func([StringHelper::class, 'getCurrencyCode']);
$result = StringHelper::getCurrencyCode();
$this->assertEquals($expectedResult, $result);
}
}

View File

@ -17,7 +17,7 @@ class TimeZoneTest extends \PHPUnit_Framework_TestCase
];
foreach ($timezoneValues as $timezoneValue) {
$result = call_user_func([TimeZone::class, 'setTimezone'], $timezoneValue);
$result = TimeZone::setTimezone($timezoneValue);
$this->assertTrue($result);
}
}
@ -25,7 +25,7 @@ class TimeZoneTest extends \PHPUnit_Framework_TestCase
public function testSetTimezoneWithInvalidValue()
{
$unsupportedTimezone = 'Etc/GMT+10';
$result = call_user_func([TimeZone::class, 'setTimezone'], $unsupportedTimezone);
$result = TimeZone::setTimezone($unsupportedTimezone);
$this->assertFalse($result);
}
}