Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,29 @@ run-tests.log
/test/*/*/*/*.log
/test/*/*/*/*.out


# Added by horde-components QC --fix-qc-issues
# Build artifacts directory
/build/
# Composer dependencies directory
/vendor/
# Composer lock file (libraries should not commit lock files)
/composer.lock
# PHPStorm IDE settings
/.idea/
# VSCode IDE settings
/.vscode/
# Claude Code CLI cache and state
/.claude/
# Cline extension data
/.cline/
# PHP CS Fixer cache file
/.php-cs-fixer.cache
# PHPUnit result cache
/.phpunit.result.cache
# PHPUnit Cache (other)
/.phpunit.cache
# PHPStan local configuration
/phpstan.neon
# PHPStan cache directory
/.phpstan.cache/
6 changes: 5 additions & 1 deletion .horde.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,12 @@ license:
uri: http://www.horde.org/licenses/lgpl21
dependencies:
required:
php: ^7.4 || ^8
php: ^8.1
composer:
horde/exception: ^3
horde/log: ^3
horde/util: ^3
keywords:
- wrapper
- minifier
vendor: horde
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
},
"autoload-dev": {
"psr-4": {
"Horde\\JavascriptMinify\\Test\\": "test/"
"Horde\\JavascriptMinify\\Test\\": "test/unit/",
"Horde\\JavascriptMinify\\Test\\Integration\\": "test/integration/"
}
},
"config": {
Expand Down
21 changes: 11 additions & 10 deletions lib/Horde/JavascriptMinify.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Copyright 2014-2017 Horde LLC (http://www.horde.org/)
* Copyright 2014-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand Down Expand Up @@ -34,7 +35,7 @@ abstract class Horde_JavascriptMinify
*
* @var array
*/
protected $_opts = array();
protected $_opts = [];

/**
* Temporary file containing sourcemap data.
Expand All @@ -51,7 +52,7 @@ abstract class Horde_JavascriptMinify
* containing the JS data to compress.
* @param array $opts Additional options. See setOptions().
*/
public function __construct($js, array $opts = array())
public function __construct($js, array $opts = [])
{
if (!is_array($js) && !is_string($js)) {
throw new InvalidArgumentException('First argument must either be an array or a string.');
Expand All @@ -77,13 +78,13 @@ public function __toString()
* - logger: (Horde_Log_Logger) Log object to use for log messages.
* </pre>
*/
public function setOptions(array $opts = array())
public function setOptions(array $opts = [])
{
$this->_opts = array_merge($this->_opts, $opts);

// Ensure we have a logger object.
if (!isset($this->_opts['logger']) ||
!($this->_opts['logger'] instanceof Horde_Log_Logger)) {
if (!isset($this->_opts['logger'])
|| !($this->_opts['logger'] instanceof Horde_Log_Logger)) {
$this->_opts['logger'] = new Horde_Log_Logger(
new Horde_Log_Handler_Null()
);
Expand All @@ -108,17 +109,17 @@ abstract public function minify();
*/
public function sourcemap()
{
if (is_null($this->_sourcemap) ||
!is_readable($this->_sourcemap) ||
!strlen($sourcemap = file_get_contents($this->_sourcemap))) {
if (is_null($this->_sourcemap)
|| !is_readable($this->_sourcemap)
|| !strlen($sourcemap = file_get_contents($this->_sourcemap))) {
return null;
}

/* Sourcemap data is JSON encoded. Need to grab 'sources', which
* contains filenames, and convert to URLs. */
$sourcemap = json_decode($sourcemap);
$data_lookup = array_flip($this->_data);
$new_sources = array();
$new_sources = [];

foreach ($sourcemap->sources as $val) {
$new_sources[] = $data_lookup[$val];
Expand Down
17 changes: 9 additions & 8 deletions lib/Horde/JavascriptMinify/Closure.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Copyright 2014-2017 Horde LLC (http://www.horde.org/)
* Copyright 2014-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand Down Expand Up @@ -32,9 +33,9 @@ class Horde_JavascriptMinify_Closure extends Horde_JavascriptMinify_Null
* sourcemap file will be stored at.
* </pre>
*/
public function setOptions(array $opts = array())
public function setOptions(array $opts = [])
{
foreach (array('closure', 'java') as $val) {
foreach (['closure', 'java'] as $val) {
if (!isset($opts[$val])) {
throw new InvalidArgumentException(
sprintf('Missing required %s option.', $val)
Expand All @@ -49,8 +50,8 @@ public function setOptions(array $opts = array())
*/
public function minify()
{
if (!is_executable($this->_opts['java']) ||
!is_readable($this->_opts['closure'])) {
if (!is_executable($this->_opts['java'])
|| !is_readable($this->_opts['closure'])) {
$this->_opts['logger']->log(
'The java path or Closure location can not be accessed.',
Horde_Log::ERR
Expand All @@ -64,9 +65,9 @@ public function minify()
$cmd = trim(escapeshellcmd($this->_opts['java']) . ' -jar ' . escapeshellarg($this->_opts['closure']) . ' --warning_level QUIET');
if (isset($this->_opts['sourcemap']) && is_array($this->_data)) {
$this->_sourcemap = Horde_Util::getTempFile();
$cmd .= ' --create_source_map ' .
escapeshellarg($this->_sourcemap) .
' --source_map_format=V3';
$cmd .= ' --create_source_map '
. escapeshellarg($this->_sourcemap)
. ' --source_map_format=V3';
$suffix = "\n//# sourceMappingURL=" . $this->_opts['sourcemap'];
} else {
$suffix = '';
Expand Down
9 changes: 4 additions & 5 deletions lib/Horde/JavascriptMinify/Exception.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Copyright 2014-2017 Horde LLC (http://www.horde.org/)
* Copyright 2014-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand All @@ -14,7 +15,7 @@
/**
* Exception handler for the Horde_JavascriptMinify package.
*
* Copyright 2014-2017 Horde LLC (http://www.horde.org/)
* Copyright 2014-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand All @@ -25,6 +26,4 @@
* @license http://www.horde.org/licenses/lgpl21 LGPL 2.1
* @package JavascriptMinify
*/
class Horde_JavascriptMinify_Exception extends Horde_Exception_Wrapped
{
}
class Horde_JavascriptMinify_Exception extends Horde_Exception_Wrapped {}
3 changes: 2 additions & 1 deletion lib/Horde/JavascriptMinify/Null.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Copyright 2014-2017 Horde LLC (http://www.horde.org/)
* Copyright 2014-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand Down
13 changes: 7 additions & 6 deletions lib/Horde/JavascriptMinify/Uglifyjs.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Copyright 2014-2017 Horde LLC (http://www.horde.org/)
* Copyright 2014-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand Down Expand Up @@ -33,7 +34,7 @@ class Horde_JavascriptMinify_Uglifyjs extends Horde_JavascriptMinify_Null
* - uglifyjs: (string) [REQUIRED] Path to the UglifyJS binary.
* </pre>
*/
public function setOptions(array $opts = array())
public function setOptions(array $opts = [])
{
if (!isset($opts['uglifyjs'])) {
throw new InvalidArgumentException('Missing required uglifyjs option.');
Expand All @@ -58,10 +59,10 @@ public function minify()
/* Sourcemaps only supported by UglifyJS2. */
if (isset($this->_opts['sourcemap']) && is_array($this->_data)) {
$this->_sourcemap = Horde_Util::getTempFile();
$cmd .= ' --source-map ' .
escapeshellarg($this->_sourcemap) .
' --source-map-url ' .
escapeshellarg($this->_opts['sourcemap']);
$cmd .= ' --source-map '
. escapeshellarg($this->_sourcemap)
. ' --source-map-url '
. escapeshellarg($this->_opts['sourcemap']);
}
if (isset($this->_opts['cmdline'])) {
$cmd .= ' ' . $this->_opts['cmdline'];
Expand Down
13 changes: 7 additions & 6 deletions lib/Horde/JavascriptMinify/Util/Cmdline.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Copyright 2014-2017 Horde LLC (http://www.horde.org/)
* Copyright 2014-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand Down Expand Up @@ -33,11 +34,11 @@ class Horde_JavascriptMinify_Util_Cmdline
*/
public function runCmd($text, $cmd, Horde_Log_Logger $log)
{
$descspec = array(
0 => array('pipe', 'r'),
1 => array('pipe', 'w'),
2 => array('pipe', 'w')
);
$descspec = [
0 => ['pipe', 'r'],
1 => ['pipe', 'w'],
2 => ['pipe', 'w'],
];

$process = proc_open($cmd, $descspec, $pipes);

Expand Down
15 changes: 8 additions & 7 deletions lib/Horde/JavascriptMinify/Yui.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

/**
* Copyright 2014-2017 Horde LLC (http://www.horde.org/)
* Copyright 2014-2026 Horde LLC (http://www.horde.org/)
*
* See the enclosed file LICENSE for license information (LGPL). If you
* did not receive this file, see http://www.horde.org/licenses/lgpl21.
Expand Down Expand Up @@ -30,9 +31,9 @@ class Horde_JavascriptMinify_Yui extends Horde_JavascriptMinify_Null
* - yui: (string) [REQUIRED] Path to the YUI compressor.
* </pre>
*/
public function setOptions(array $opts = array())
public function setOptions(array $opts = [])
{
foreach (array('java', 'yui') as $val) {
foreach (['java', 'yui'] as $val) {
if (!isset($opts[$val])) {
throw new InvalidArgumentException(
sprintf('Missing required %s option.', $val)
Expand All @@ -49,8 +50,8 @@ public function minify()
{
$js = parent::minify();

if (!is_executable($this->_opts['java']) ||
!is_readable($this->_opts['yui'])) {
if (!is_executable($this->_opts['java'])
|| !is_readable($this->_opts['yui'])) {
$this->_opts['logger']->log(
'The java path or YUI location can not be accessed.',
Horde_Log::ERR
Expand All @@ -64,8 +65,8 @@ public function minify()
}

$cmdline = new Horde_JavascriptMinify_Util_Cmdline();
return $cmdline->runCmd($js, trim($cmd), $this->_opts['logger']) .
$this->_sourceUrls();
return $cmdline->runCmd($js, trim($cmd), $this->_opts['logger'])
. $this->_sourceUrls();
}

}
39 changes: 27 additions & 12 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="test/Horde/JavascriptMinify/bootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">lib</directory>
</include>
</coverage>
<testsuites>
<testsuite name="horde/JavascriptMinify">
<directory>test</directory>
</testsuite>
</testsuites>
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.0/phpunit.xsd"
bootstrap="vendor/autoload.php"
cacheDirectory=".phpunit.cache"
colors="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerErrors="true"
displayDetailsOnTestsThatTriggerNotices="true"
displayDetailsOnTestsThatTriggerWarnings="true"
failOnDeprecation="true"
failOnNotice="true"
failOnWarning="true"
defaultTestSuite="unit">
<testsuites>
<testsuite name="unit">
<directory>test/unit</directory>
</testsuite>
<testsuite name="integration">
<directory>test/integration</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">lib</directory>
</include>
</source>
</phpunit>
5 changes: 0 additions & 5 deletions test/Horde/JavascriptMinify/AllTests.php

This file was deleted.

Loading