Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 388a938

Browse filesBrowse files
AC-9098:Ability to use Adobe copyright for Adobe Commerce source code for Magento Open Source (CE)-Validation
1 parent 7521587 commit 388a938
Copy full SHA for 388a938
Expand file treeCollapse file tree

10 files changed

+79
-65
lines changed

‎Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php

Copy file name to clipboardExpand all lines: Magento2Framework/Sniffs/Header/CopyrightAnotherExtensionsFilesSniff.php
+9-16Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212

1313
class CopyrightAnotherExtensionsFilesSniff implements Sniff
1414
{
15+
use CopyrightValidation;
1516
private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat';
1617

17-
private const COPYRIGHT_MAGENTO_TEXT = 'Copyright © Magento, Inc. All rights reserved.';
18-
private const COPYRIGHT_ADOBE = '/Copyright \d+ Adobe/';
19-
private const COPYRIGHT_ADOBE_TEXT = 'ADOBE CONFIDENTIAL';
20-
2118
/**
2219
* Defines the tokenizers that this sniff is using.
2320
*
@@ -45,19 +42,15 @@ public function process(File $phpcsFile, $stackPtr)
4542
return;
4643
}
4744

48-
$fileText = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens()));
45+
// @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged
46+
$content = file_get_contents($phpcsFile->getFilename());
4947

50-
if (strpos($fileText, self::COPYRIGHT_MAGENTO_TEXT) !== false
51-
|| preg_match(self::COPYRIGHT_ADOBE, $fileText)
52-
|| strpos($fileText, self::COPYRIGHT_ADOBE_TEXT) !== false
53-
) {
54-
return;
48+
if ($this->isCopyrightYearValid($content) === false) {
49+
$phpcsFile->addWarningOnLine(
50+
'Copyright is missing or has wrong format',
51+
null,
52+
self::WARNING_CODE
53+
);
5554
}
56-
57-
$phpcsFile->addWarningOnLine(
58-
'Copyright is missing or has wrong format',
59-
null,
60-
self::WARNING_CODE
61-
);
6255
}
6356
}

‎Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php

Copy file name to clipboardExpand all lines: Magento2Framework/Sniffs/Header/CopyrightGraphQLSniff.php
+7-14Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,9 @@
1212

1313
class CopyrightGraphQLSniff implements Sniff
1414
{
15+
use CopyrightValidation;
1516
private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat';
1617

17-
private const COPYRIGHT_MAGENTO_TEXT = 'Copyright © Magento, Inc. All rights reserved.';
18-
private const COPYRIGHT_ADOBE = '/Copyright \d+ Adobe/';
19-
private const COPYRIGHT_ADOBE_TEXT = 'ADOBE CONFIDENTIAL';
20-
2118
private const FILE_EXTENSION = 'graphqls';
2219

2320
/**
@@ -45,16 +42,12 @@ public function process(File $phpcsFile, $stackPtr)
4542
// @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged
4643
$content = file_get_contents($phpcsFile->getFilename());
4744

48-
if (strpos($content, self::COPYRIGHT_MAGENTO_TEXT) !== false
49-
|| preg_match(self::COPYRIGHT_ADOBE, $content)
50-
|| strpos($content, self::COPYRIGHT_ADOBE_TEXT) !== false) {
51-
return;
45+
if ($this->isCopyrightYearValid($content) === false) {
46+
$phpcsFile->addWarningOnLine(
47+
'Copyright is missing or has wrong format',
48+
null,
49+
self::WARNING_CODE
50+
);
5251
}
53-
54-
$phpcsFile->addWarningOnLine(
55-
'Copyright is missing or has wrong format',
56-
null,
57-
self::WARNING_CODE
58-
);
5952
}
6053
}

‎Magento2Framework/Sniffs/Header/CopyrightSniff.php

Copy file name to clipboardExpand all lines: Magento2Framework/Sniffs/Header/CopyrightSniff.php
+12-18Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2021 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types = 1);
77

@@ -12,11 +12,9 @@
1212

1313
class CopyrightSniff implements Sniff
1414
{
15-
private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat';
15+
use CopyrightValidation;
1616

17-
private const COPYRIGHT_MAGENTO_TEXT = 'Copyright © Magento, Inc. All rights reserved.';
18-
private const COPYRIGHT_ADOBE = '/Copyright \d+ Adobe/';
19-
private const COPYRIGHT_ADOBE_TEXT = 'ADOBE CONFIDENTIAL';
17+
private const WARNING_CODE = 'FoundCopyrightMissingOrWrongFormat';
2018

2119
/**
2220
* @inheritdoc
@@ -46,19 +44,15 @@ public function process(File $phpcsFile, $stackPtr)
4644
return;
4745
}
4846

49-
$content = $phpcsFile->getTokens()[$positionComment]['content'];
50-
$adobeCopyrightFound = preg_match(self::COPYRIGHT_ADOBE, $content);
47+
// @phpcs:ignore Magento2.Functions.DiscouragedFunction.Discouraged
48+
$content = file_get_contents($phpcsFile->getFilename());
5149

52-
if (strpos($content, self::COPYRIGHT_MAGENTO_TEXT) !== false ||
53-
$adobeCopyrightFound ||
54-
strpos($content, self::COPYRIGHT_ADOBE_TEXT) !== false) {
55-
return;
50+
if ($this->isCopyrightYearValid($content) === false) {
51+
$phpcsFile->addWarningOnLine(
52+
'Copyright is missing or has wrong format',
53+
null,
54+
self::WARNING_CODE
55+
);
5656
}
57-
58-
$phpcsFile->addWarningOnLine(
59-
'Copyright is missing or has wrong format',
60-
$phpcsFile->getTokens()[$positionComment]['line'],
61-
self::WARNING_CODE
62-
);
6357
}
6458
}
+33Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
5+
*/
6+
declare(strict_types = 1);
7+
8+
namespace Magento2Framework\Sniffs\Header;
9+
10+
trait CopyrightValidation
11+
{
12+
13+
/**
14+
* Check is copyright year valid or not
15+
*
16+
* @param string $content
17+
* @return bool
18+
*/
19+
private function isCopyrightYearValid(string $content): bool
20+
{
21+
$pattern = '/Copyright (\d{4}) Adobe/';
22+
if (preg_match($pattern, $content, $matches)) {
23+
$year = (int) $matches[1];
24+
if ($year >= 2010 && $year <= date("Y")) {
25+
return true;
26+
} else {
27+
return false;
28+
}
29+
} else {
30+
return false;
31+
}
32+
}
33+
}

‎Magento2Framework/Tests/Header/CopyrightAnotherExtensionsFilesUnitTest.4.js

Copy file name to clipboardExpand all lines: Magento2Framework/Tests/Header/CopyrightAnotherExtensionsFilesUnitTest.4.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
2-
* Copyright © Magento, Inc. All rights reserved.
3-
* See COPYING.txt for license details.
2+
* Copyright 2021 Adobe
3+
* All Rights Reserved.
44
*/
55

66
define([

‎Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.1.graphqls

Copy file name to clipboardExpand all lines: Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.1.graphqls
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
# Copyright © Magento, Inc. All rights reserved.
2-
# See COPYING.txt for license details.
1+
# Copyright 2021 Adobe
2+
# All Rights Reserved.
33

44
enum PriceAdjustmentCodesEnum {
55
WEEE @deprecated(reason: "WEEE code is deprecated, use fixed_product_taxes.label")

‎Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.2.graphqls

Copy file name to clipboardExpand all lines: Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.2.graphqls
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Copyright 2020 Adobe
2-
# See COPYING.txt for license details.
2+
# All Rights Reserved.
33

44
enum PriceAdjustmentCodesEnum {
55
WEEE @deprecated(reason: "WEEE code is deprecated, use fixed_product_taxes.label")

‎Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php

Copy file name to clipboardExpand all lines: Magento2Framework/Tests/Header/CopyrightGraphQLUnitTest.php
+9-9Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,28 +9,28 @@
99

1010
class CopyrightGraphQLUnitTest extends AbstractGraphQLSniffUnitTestCase
1111
{
12-
/**
13-
* @inheritdoc
14-
*/
12+
/**
13+
* @inheritdoc
14+
*/
1515
public function getErrorList(): array
1616
{
1717
return [];
1818
}
1919

20-
/**
21-
* @inheritdoc
22-
*/
20+
/**
21+
* @inheritdoc
22+
*/
2323
public function getWarningList($testFile = ''): array
2424
{
2525
if ($testFile === 'CopyrightGraphQLUnitTest.1.graphqls' ||
26-
$testFile === 'CopyrightGraphQLUnitTest.2.graphqls') {
26+
$testFile === 'CopyrightGraphQLUnitTest.2.graphqls') {
2727
return [];
2828
}
2929

3030
if ($testFile === 'CopyrightGraphQLUnitTest.3.graphqls' ||
31-
$testFile === 'CopyrightGraphQLUnitTest.4.graphqls') {
31+
$testFile === 'CopyrightGraphQLUnitTest.4.graphqls') {
3232
return [
33-
null => 1
33+
null => 1
3434
];
3535
}
3636

+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2021 Adobe
4+
* All Rights Reserved.
55
*/
66

77

‎Magento2Framework/Tests/Header/CopyrightUnitTest.php

Copy file name to clipboardExpand all lines: Magento2Framework/Tests/Header/CopyrightUnitTest.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ public function getWarningList($testFile = ''): array
3131
1 => 1,
3232
];
3333
}
34+
3435
if ($testFile === 'CopyrightUnitTest.2.inc' || $testFile === 'CopyrightUnitTest.3.inc') {
3536
return [
36-
3 => 1,
37+
null => 1,
3738
];
3839
}
3940

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.