Wednesday, 6 July 2022

Magento 2 Coding Standard warning fixed

 Magento Coding Standard  warning fixed



First we add DocBlock on all pages at top like this

<?php

/**

 * Copyright © Magento, Inc. All rights reserved.

 * See COPYING.txt for license details.

 */


WARNING | Short description duplicates class property name.

WARNING | Missing short description

WARNING | There must be exactly one blank line before tags

WARNING | Type is not specified


---------------------WARNING | Short description duplicates class property name.

/**

 * Url Builder

 *

 * @var UrlInterface

 */

protected $_urlBuilder;


..........Replace to

/**

 * Builder a Url

 *

 * @var urlBuilder

 */

 

---------------------WARNING | Missing short description

/**

 * @param \Magento\Checkout\CustomerData\Cart $subject

 * @param $result

 *

 * @return mixed

 * @throws LocalizedException

 * @throws NoSuchEntityException

 */

 

 .........Replace to

 

/**

 * After Plugin Get Section Data

 *

 * @param $result

 *

 * @return mixed

 *

 * @throws LocalizedException

 * @throws NoSuchEntityException

 */

 

 

----------------------WARNING | There must be exactly one blank line before tags

 

/**

* After Plugin Get Section Data

*

* @param $result

*

* @return mixed

* @throws LocalizedException

* @throws NoSuchEntityException

*/

 .........Replace to

 

/**

 * After Plugin Get Section Data

 *

 * @param $result

 *

 * @return mixed

 *

 * @throws LocalizedException

 * @throws NoSuchEntityException

 */

 

 ----------------------WARNING | Type is not specified

 

 /**

 * After Plugin Get Section Data

 *

 * @param $result

 *

 * @return mixed

 *

 */

public function afterGetSectionData($result)


............Replace to @param array $result


/**

 * After Plugin Get Section Data

 *

 * @param array $result

 *

 * @return mixed

 *

 */

 more example like this

 /**

 * Validates that forbidden tags are not used in comment

 *

 * @param File $phpcsFile

 * @param int $commentStartPtr

 * @param array $tokens

 * @return bool

 */

private function validateTags(File $phpcsFile, $commentStartPtr, $tokens)


WARNING | Short description must start with a capital letter

/**

 * set cart token

 *

 * @param CartInterface $cart

 *

 * @return CartInterface

 */

 .............. Replace to

/**

 * Set Cart Token

 *

 * @param CartInterface $cart

 *

 * @return CartInterface

 */





WARNING | Line exceeds 120 characters; contains 133 characters

$tcpdf2 = new \Eighteentech\DownloadQuote\Block\Tcpdf\MYTCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);


.............. Replace to


$tcpdf2 = new \Eighteentech\DownloadQuote\Block\Tcpdf\MYTCPDF(

            PDF_PAGE_ORIENTATION,

            PDF_UNIT,

            PDF_PAGE_FORMAT,

            true,

            'UTF-8',

            false

        );

        

WARNING | Comment block is missing


public function getCmsFilterContent($value = '')

 

.............. Replace to

 

/**

 * Cms Filter Content

 *

 * @param voide $value

 */

public function getCmsFilterContent($value = '')



WARNING | The use of function unlink() is discouraged


unlink($pdffilepath);


.............. Replace to all files related solution

First you add like this

use Magento\Framework\Filesystem\Io\File;


/** @var File */

private $file;


/**

 * @param File $file

 */

public function __construct(File $file)

{

$this->file = $file;

}


file_exist() can be

$this->file->fileExists($file);


unlink() can be

$this->file->rm($file)


mkdir() can be

$this->file->mkdir($dir)


`dirname() can be

$this->file->dirname($file)


file_put_contents() can be

$this->file->write($filename, $src, $mode)


No comments:

Post a Comment