Method testCreateTemplate
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function testCreateTemplate()
{
$this->fileName = uniqid() . '.pdf';
$pdfModel = \Settings_PDF_Record_Model::getCleanInstance(self::MODULE_NAME);
$pdfModel->set('module_name', self::MODULE_NAME);
Missing class import via use statement (line '69', column '32'). Open
$this->assertSame((int) (new \App\Db\Query())->select(['pdfid'])
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Missing class import via use statement (line '95', column '27'). Open
$this->assertFalse((new \App\Db\Query())->select(['pdfid'])
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
Avoid using static access to class '\Settings_PDF_Record_Model' in method 'testCreateTemplate'. Open
\Settings_PDF_Record_Model::save($pdfModel, 'import');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Db' in method 'testRemoveTemplate'. Open
->exists(\App\Db::getInstance('admin')), 'Not removed template');
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\App\Pdf\Pdf' in method 'testGenerate'. Open
$pdf = \App\Pdf\Pdf::getInstanceByTemplateId(self::$pdfModel->get('pdfid'));
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Settings_PDF_Record_Model' in method 'testCreateTemplate'. Open
$pdfModel = \Settings_PDF_Record_Model::getCleanInstance(self::MODULE_NAME);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\Settings_PDF_Record_Model' in method 'testRemoveTemplate'. Open
\Settings_PDF_Record_Model::delete(self::$pdfModel);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Define a constant instead of duplicating this literal "module_name" 3 times. Open
$pdfModel->set('module_name', self::MODULE_NAME);
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "primary_name" 3 times. Open
$pdfModel->set('primary_name', 'test');
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Rename "$pdfModel" which has the same name as the field declared at line 33. Open
$pdfModel = \Settings_PDF_Record_Model::getCleanInstance(self::MODULE_NAME);
- Read upRead up
- Exclude checks
Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.
Noncompliant Code Example
class Foo { public $myField; public function doSomething() { $myField = 0; ... } }
See
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Define a constant instead of duplicating this literal "pdfid" 4 times. Open
$this->assertSame((int) (new \App\Db\Query())->select(['pdfid'])
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "filename" 3 times. Open
$pdfModel->set('filename', $this->fileName);
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Call to undeclared method \App\Db\Query::select
Open
$this->assertFalse((new \App\Db\Query())->select(['pdfid'])
- Exclude checks
Call to undeclared method \App\Db\Query::select
Open
$this->assertSame((int) (new \App\Db\Query())->select(['pdfid'])
- Exclude checks
Call to undeclared method \Tests\Settings\Pdf::assertSame
Open
$this->assertSame((int) (new \App\Db\Query())->select(['pdfid'])
- Exclude checks
Call to undeclared method \Tests\Settings\Pdf::assertFileExists
Open
$this->assertFileExists($pathToFile);
- Exclude checks
Call to undeclared method \Tests\Settings\Pdf::assertFalse
Open
$this->assertFalse((new \App\Db\Query())->select(['pdfid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const MODULE_NAME = 'Accounts';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->fileName = uniqid() . '.pdf';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('margin_left', 15);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('body_content', 'Test Body');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Temporary model.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('module_name', self::MODULE_NAME);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('styles', '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertFileExists($pathToFile);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Testing removing template.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Module name.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('margin_right', 15);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->exists(\App\Db::getInstance('admin')), 'Not removed template');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('metatags_status', 1);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\Settings_PDF_Record_Model::save($pdfModel, 'import');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function testRemoveTemplate()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public $fileName = 'test.pdf';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @var \Settings_PDF_Record_Model
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* File name.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['module_name' => self::MODULE_NAME, 'filename' => $this->fileName, 'primary_name' => 'test'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdf->getTemplate()->setVariable('recordId', \Tests\Base\C_RecordActions::createAccountRecord()->getId());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('generator', 'YetiForcePDF');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('primary_name', 'test');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('watermark_type', 0);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Testing creating template.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('margin_top', 15);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('header_content', 'Test Header');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdf = \App\Pdf\Pdf::getInstanceByTemplateId(self::$pdfModel->get('pdfid'));
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertFalse((new \App\Db\Query())->select(['pdfid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('filename', $this->fileName);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('status', 1);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('page_format', 'A4');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('page_orientation', 'PLL_PORTRAIT');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('visibility', 'PLL_LISTVIEW,PLL_DETAILVIEW');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('a_#__pdf')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Testing PDF generation.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdf->loadTemplateData();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\Settings_PDF_Record_Model::delete(self::$pdfModel);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pathToFile = ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . 'cache/pdf/' . $this->fileName;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
\unlink($pathToFile);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function testCreateTemplate()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('language', 'pl-PL');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('margin_bottom', 15);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel = \Settings_PDF_Record_Model::getCleanInstance(self::MODULE_NAME);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('watermark_size', 0);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$this->assertSame((int) (new \App\Db\Query())->select(['pdfid'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('watermark_angle', 0);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->scalar(), (int) $pdfModel->get('pdfid'), 'Not created template');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->where(['module_name' => self::MODULE_NAME, 'filename' => $this->fileName, 'primary_name' => 'test'])
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
private static $pdfModel;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public function testGenerate()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
->from('a_#__pdf')
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\file_exists($pathToFile)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('watermark_image', '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('header_height', 10);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('footer_height', 10);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('footer_content', 'Test Footer');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('watermark_text', '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdfModel->set('template_members', '');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
self::$pdfModel = $pdfModel;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pathToFile = ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . 'cache/pdf/' . $this->fileName;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$pdf->output($pathToFile, 'F');
- Exclude checks