FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
phpstan-src/.github/scripts/diffPrefixes.php at 2.2.x · predictor2718/phpstan-src · GitHub
predictor2718
/
phpstan-src
Public
forked from
phpstan/phpstan-src
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
phpstan-src
/
.github
/
scripts
/
diffPrefixes.php
Copy path
More file actions
More file actions
Latest commit
History
History
History
85 lines (70 loc) · 1.81 KB
Breadcrumbs
phpstan-src
/
.github
/
scripts
/
diffPrefixes.php
Copy path
File metadata and controls
85 lines (70 loc) · 1.81 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
declare
(strict_types =
1
);
use
Nette
\
Utils
\
Strings
;
use
SebastianBergmann
\
Diff
\
Differ
;
require_once
__DIR__
.
'
/../../vendor/autoload.php
'
;
$
diffFile
=
$
argv
[
1
] ??
null
;
$
oldDir
=
$
argv
[
2
] ??
null
;
$
newDir
=
$
argv
[
3
] ??
null
;
if
(
$
diffFile
===
null
|| !
is_file
(
$
diffFile
)) {
exit
(
1
);
}
if
(
$
oldDir
===
null
|| !
is_dir
(
$
oldDir
)) {
exit
(
1
);
}
if
(
$
newDir
===
null
|| !
is_dir
(
$
newDir
)) {
exit
(
1
);
}
$
diffLines
=
explode
(
"\n"
,
file_get_contents
(
$
diffFile
));
$
differ
=
new
Differ
(
new
\
SebastianBergmann
\
Diff
\
Output
\
UnifiedDiffOutputBuilder
(
''
,
true
));
$
isDifferent
=
false
;
foreach
(
$
diffLines
as
$
diffLine
) {
$
operation
=
$
diffLine
[
0
];
if
(
$
operation
===
'
'
) {
continue
;
}
$
pathWithLine
=
substr
(
$
diffLine
,
1
);
$
pathParts
=
explode
(
'
:
'
,
$
pathWithLine
);
$
path
=
$
pathParts
[
0
];
$
lineNumber
=
$
pathParts
[
1
] ??
null
;
if
(
$
lineNumber
===
null
) {
continue
;
}
$
oldFilePath
=
$
oldDir
.
'
/
'
.
$
path
;
if
(!
is_file
(
$
oldFilePath
)) {
continue
;
}
$
newFilePath
=
$
newDir
.
'
/
'
.
$
path
;
if
(!
is_file
(
$
newFilePath
)) {
continue
;
}
$
stringDiff
=
$
differ
->
diff
(
file_get_contents
(
$
oldFilePath
),
file_get_contents
(
$
newFilePath
));
if
(
$
stringDiff
===
''
) {
continue
;
}
$
isDifferent
=
true
;
echo
"
$
path
:
\n"
;
$
startLine
=
1
;
$
startContext
=
1
;
foreach
(
explode
(
"\n"
,
$
stringDiff
)
as
$
i
=>
$
line
) {
$
matches
= Strings::
match
(
$
line
,
'
/^@@ -(\d+),?(\d*) \+(\d+),?(\d*) @@/
'
);
if
(
$
matches
!==
null
) {
$
startLine
= (
int
)
$
matches
[
1
];
$
startContext
= (
int
)
$
matches
[
2
];
continue
;
}
if
(
$
lineNumber
<
$
startLine
||
$
lineNumber
> (
$
startLine
+
$
startContext
)) {
continue
;
}
if
(
str_starts_with
(
$
line
,
'
+
'
)) {
echo
"\033
[32m
$
line
\033
[0m
\n"
;
}
elseif
(
str_starts_with
(
$
line
,
'
-
'
)) {
echo
"\033
[31m
$
line
\033
[0m
\n"
;
}
else
{
echo
"
$
line
\n"
;
}
}
echo
"\n"
;
}
if
(
$
isDifferent
) {
exit
(
1
);
}
Back
|
FazBrowse Home
|
New Git URL