1
0
mirror of https://github.com/Ne-Lexa/php-zip.git synced 2025-10-18 08:36:51 +02:00

php cs fix

This commit is contained in:
Ne-Lexa
2019-12-05 19:36:11 +03:00
parent ca068fa78f
commit 3bafe01ff0
62 changed files with 5315 additions and 2459 deletions

View File

@@ -8,18 +8,15 @@ namespace PhpZip\Model;
*/
class ZipEntryMatcher implements \Countable
{
/**
* @var ZipModel
*/
/** @var ZipModel */
protected $zipModel;
/**
* @var array
*/
/** @var array */
protected $matches = [];
/**
* ZipEntryMatcher constructor.
*
* @param ZipModel $zipModel
*/
public function __construct(ZipModel $zipModel)
@@ -29,44 +26,59 @@ class ZipEntryMatcher implements \Countable
/**
* @param string|array $entries
*
* @return ZipEntryMatcher
*/
public function add($entries)
{
$entries = (array)$entries;
$entries = array_map(function ($entry) {
return $entry instanceof ZipEntry ? $entry->getName() : $entry;
}, $entries);
$this->matches = array_unique(
array_merge(
$this->matches,
array_keys(
array_intersect_key(
$this->zipModel->getEntries(),
array_flip($entries)
$entries = (array) $entries;
$entries = array_map(
static function ($entry) {
return $entry instanceof ZipEntry ? $entry->getName() : (string) $entry;
},
$entries
);
$this->matches = array_values(
array_map(
'strval',
array_unique(
array_merge(
$this->matches,
array_keys(
array_intersect_key(
$this->zipModel->getEntries(),
array_flip($entries)
)
)
)
)
)
);
return $this;
}
/**
* @param string $regexp
*
* @return ZipEntryMatcher
*/
public function match($regexp)
{
array_walk($this->zipModel->getEntries(), function (
/** @noinspection PhpUnusedParameterInspection */
$entry,
$entryName
) use ($regexp) {
if (preg_match($regexp, $entryName)) {
$this->matches[] = $entryName;
array_walk(
$this->zipModel->getEntries(),
function (
/** @noinspection PhpUnusedParameterInspection */
$entry,
$entryName
) use ($regexp) {
if (preg_match($regexp, $entryName)) {
$this->matches[] = (string) $entryName;
}
}
});
);
$this->matches = array_unique($this->matches);
return $this;
}
@@ -76,6 +88,7 @@ class ZipEntryMatcher implements \Countable
public function all()
{
$this->matches = array_keys($this->zipModel->getEntries());
return $this;
}
@@ -90,9 +103,12 @@ class ZipEntryMatcher implements \Countable
public function invoke(callable $callable)
{
if (!empty($this->matches)) {
array_walk($this->matches, function ($entryName) use ($callable) {
call_user_func($callable, $entryName);
});
array_walk(
$this->matches,
static function ($entryName) use ($callable) {
$callable($entryName);
}
);
}
}
@@ -106,24 +122,31 @@ class ZipEntryMatcher implements \Countable
public function delete()
{
array_walk($this->matches, function ($entry) {
$this->zipModel->deleteEntry($entry);
});
array_walk(
$this->matches,
function ($entry) {
$this->zipModel->deleteEntry($entry);
}
);
$this->matches = [];
}
/**
* @param string|null $password
* @param int|null $encryptionMethod
* @param int|null $encryptionMethod
*/
public function setPassword($password, $encryptionMethod = null)
{
array_walk($this->matches, function ($entry) use ($password, $encryptionMethod) {
$entry = $this->zipModel->getEntry($entry);
if (!$entry->isDirectory()) {
$this->zipModel->getEntryForChanges($entry)->setPassword($password, $encryptionMethod);
array_walk(
$this->matches,
function ($entry) use ($password, $encryptionMethod) {
$entry = $this->zipModel->getEntry($entry);
if (!$entry->isDirectory()) {
$this->zipModel->getEntryForChanges($entry)->setPassword($password, $encryptionMethod);
}
}
});
);
}
/**
@@ -131,36 +154,47 @@ class ZipEntryMatcher implements \Countable
*/
public function setEncryptionMethod($encryptionMethod)
{
array_walk($this->matches, function ($entry) use ($encryptionMethod) {
$entry = $this->zipModel->getEntry($entry);
if (!$entry->isDirectory()) {
$this->zipModel->getEntryForChanges($entry)->setEncryptionMethod($encryptionMethod);
array_walk(
$this->matches,
function ($entry) use ($encryptionMethod) {
$entry = $this->zipModel->getEntry($entry);
if (!$entry->isDirectory()) {
$this->zipModel->getEntryForChanges($entry)->setEncryptionMethod($encryptionMethod);
}
}
});
);
}
public function disableEncryption()
{
array_walk($this->matches, function ($entry) {
$entry = $this->zipModel->getEntry($entry);
if (!$entry->isDirectory()) {
$entry = $this->zipModel->getEntryForChanges($entry);
$entry->disableEncryption();
array_walk(
$this->matches,
function ($entry) {
$entry = $this->zipModel->getEntry($entry);
if (!$entry->isDirectory()) {
$entry = $this->zipModel->getEntryForChanges($entry);
$entry->disableEncryption();
}
}
});
);
}
/**
* Count elements of an object
* @link http://php.net/manual/en/countable.count.php
* Count elements of an object.
*
* @see http://php.net/manual/en/countable.count.php
*
* @return int The custom count as an integer.
* </p>
* <p>
* The return value is cast to an integer.
* </p>
* <p>
* The return value is cast to an integer.
*
* @since 5.1.0
*/
public function count()
{
return count($this->matches);
return \count($this->matches);
}
}