Skip to content

Commit d4cf2d9

Browse files
committed
renamed FileInfo::match() to FileInfo::matchExpression()
In PHP8, `match` is a reserved keyword. In preparation this renames the method. A fallback via __call() is provided which will trigger a E_USER_NOTICE.
1 parent e84a33a commit d4cf2d9

File tree

4 files changed

+38
-11
lines changed

4 files changed

+38
-11
lines changed

src/FileInfo.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,24 @@ public function __construct($path = '')
3737
$this->setPath($path);
3838
}
3939

40+
/**
41+
* Handle calls to deprecated methods
42+
*
43+
* @param string $name
44+
* @param array $arguments
45+
* @return mixed
46+
*/
47+
public function __call($name, $arguments)
48+
{
49+
if($name === 'match') {
50+
trigger_error('FileInfo::match() is deprecated, use FileInfo::matchExpression() instead.', E_USER_NOTICE);
51+
return call_user_func_array([$this, $name], $arguments);
52+
}
53+
54+
trigger_error('Call to undefined method FileInfo::'.$name.'()', E_USER_ERROR);
55+
return null;
56+
}
57+
4058
/**
4159
* Factory to build FileInfo from existing file or directory
4260
*
@@ -324,7 +342,7 @@ public function strip($strip)
324342
* @param string $exclude Regular expression of files to exclude
325343
* @return bool
326344
*/
327-
public function match($include = '', $exclude = '')
345+
public function matchExpression($include = '', $exclude = '')
328346
{
329347
$extract = true;
330348
if ($include && !preg_match($include, $this->getPath())) {

src/Tar.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ public function extract($outdir, $strip = '', $exclude = '', $include = '')
158158
$fileinfo->strip($strip);
159159

160160
// skip unwanted files
161-
if (!strlen($fileinfo->getPath()) || !$fileinfo->match($include, $exclude)) {
161+
if (!strlen($fileinfo->getPath()) || !$fileinfo->matchExpression($include, $exclude)) {
162162
$this->skipbytes(ceil($header['size'] / 512) * 512);
163163
continue;
164164
}

src/Zip.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ public function extract($outdir, $strip = '', $exclude = '', $include = '')
142142
$fileinfo->strip($strip);
143143

144144
// skip unwanted files
145-
if (!strlen($fileinfo->getPath()) || !$fileinfo->match($include, $exclude)) {
145+
if (!strlen($fileinfo->getPath()) || !$fileinfo->matchExpression($include, $exclude)) {
146146
continue;
147147
}
148148

tests/FileInfoTest.php

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,19 +71,28 @@ public function testStrip()
7171
$this->assertEquals('baz/bang', $fileinfo->getPath());
7272
}
7373

74-
public function testMatch()
74+
public function testMatchExpression()
7575
{
7676
$fileinfo = new FileInfo('foo/bar/baz/bang');
7777

78-
$this->assertTrue($fileinfo->match());
79-
$this->assertTrue($fileinfo->match('/bang/'));
80-
$this->assertFalse($fileinfo->match('/bark/'));
78+
$this->assertTrue($fileinfo->matchExpression());
79+
$this->assertTrue($fileinfo->matchExpression('/bang/'));
80+
$this->assertFalse($fileinfo->matchExpression('/bark/'));
8181

82-
$this->assertFalse($fileinfo->match('', '/bang/'));
83-
$this->assertTrue($fileinfo->match('', '/bark/'));
82+
$this->assertFalse($fileinfo->matchExpression('', '/bang/'));
83+
$this->assertTrue($fileinfo->matchExpression('', '/bark/'));
8484

85-
$this->assertFalse($fileinfo->match('/bang/', '/foo/'));
86-
$this->assertTrue($fileinfo->match('/bang/', '/bark/'));
85+
$this->assertFalse($fileinfo->matchExpression('/bang/', '/foo/'));
86+
$this->assertTrue($fileinfo->matchExpression('/bang/', '/bark/'));
87+
}
88+
89+
/**
90+
* @expectedException \PHPUnit_Framework_Error_Notice
91+
*/
92+
public function testMatchDeprecation()
93+
{
94+
$fileinfo = new FileInfo('foo/bar/baz/bang');
95+
$fileinfo->match('/bang/', '/bark/');
8796
}
8897

8998
public function testFromPath()

0 commit comments

Comments
 (0)