Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed typos and more #20

Merged
merged 2 commits into from
Feb 12, 2024
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A set of helper classes for the Yii Framework which are used as LUYA Helpers.

## Installation

In order to install the LUYA Yii Framework Helpers use composer:
In order to install the LUYA Yii Framework Helpers use Composer:

```sh
composer require luyadev/yii-helpers
Expand All @@ -20,10 +20,10 @@ composer require luyadev/yii-helpers
The LUYA Yii Framework Helpers library provides the following classes:

+ ArrayHelper - Working with Arrays
+ ExportHelper - Export Data into a given Format (f.e. CSV, XLS)
+ ExportHelper - Export Data into a given Format (e.g. CSV, XLS)
+ ImportHelper - Import Data
+ FileHelper - Working with Filesystem
+ Json = Working with Json Data
+ Json = Working with JSON Data
+ RestHelper - Yii Framework REST API Output
+ StringHelper - Working with Strings
+ ZipHelper - Create ZIP Archives
34 changes: 17 additions & 17 deletions src/helpers/ArrayHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
/**
* Helper methods when dealing with Arrays.
*
* Extends the {{yii\helpers\ArrayHelper}} class by some usefull functions like:
* Extends the {{yii\helpers\ArrayHelper}} class by some useful functions like:
*
* + {{luya\yii\helpers\ArrayHelper::toObject()}}
* + {{luya\yii\helpers\ArrayHelper::arrayUnshiftAssoc()}}
Expand Down Expand Up @@ -39,9 +39,9 @@ public static function toObject(array $array)
}

/**
* Cover senstive values from a given list of keys.
* Cover sensitive values from a given list of keys.
*
* The main purpose is to remove passwords transferd to api when existing in post, get or session.
* The main purpose is to remove passwords transferred to API when existing in POST, GET or SESSION.
*
* Example:
*
Expand Down Expand Up @@ -73,12 +73,12 @@ public static function coverSensitiveValues(array $data, array $keys = [])
}
}

// the later overrides the former
// the latter overrides the former
return array_replace($data, $clean);
}

/**
* Prepend an assoc array item as first entry for a given array.
* Prepend an associative array item as first entry for a given array.
*
* Adds the given key with value as first entry to $arr
*
Expand All @@ -97,7 +97,7 @@ public static function arrayUnshiftAssoc(&$arr, $key, $val)
/**
* TypeCast values from a mixed array source. numeric values will be casted as integer.
*
* This method is often used to convert corect json respons arrays
* This method is often used to convert correct JSON response arrays
*
* @param array $array The array which should be type casted
* @return array An array with type casted values
Expand All @@ -120,7 +120,7 @@ public static function typeCast(array $array)
}

/**
* Search trough all keys inside of an array, any occurence will return the rest of the array.
* Search through all keys inside of an array, any occurrence will return the rest of the array.
*
* ```php
* $data = [
Expand All @@ -137,7 +137,7 @@ public static function typeCast(array $array)
* ];
* ```
*
* Searching for the string `Bar` would return the the orignal array is bar would be found in both.
* Searching for the string `Bar` would return the original array if bar would be found in both.
*
* In order to search only in certain keys defined $keys attribute:
*
Expand All @@ -149,7 +149,7 @@ public static function typeCast(array $array)
*
* @param array $array The multidimensional array keys.
* @param string $searchText The text you where search inside the rows.
* @param boolean $sensitive Whether to use strict sensitive search (true) or case insenstivie search (false).
* @param boolean $sensitive Whether to use strict sensitive search (`true`) or case insensitive search (`false`).
* @param array $keys A list of array keys which should be taken to search in, if empty or not provided it will lookup all array keys by default.
* @return array The modified array depending on the search result hits.
*/
Expand All @@ -176,9 +176,9 @@ public static function search(array $array, $searchText, $sensitive = false, arr
}

/**
* Search for a Column Value inside a Multidimension array and return the array with the found key.
* Search for a column value inside a multidimensional array and return the array with the found key.
*
* Compare to searchColumns() this function return will return the first found result.
* Compared to `searchColumns()` this function return will return the first found result.
*
* ```php
* $array = [
Expand All @@ -192,7 +192,7 @@ public static function search(array $array, $searchText, $sensitive = false, arr
* // array ('name' => 'nadar', 'userId' => 2);
* ```
*
* > This will not work with assoc keys
* > This will not work with associative keys
*
* @param array $array The array with the multimensional array values.
* @param string $column The column to lookup and compare with the $search string.
Expand All @@ -210,9 +210,9 @@ public static function searchColumn(array $array, $column, $search)
/**
* Search for columns with the given search value, returns the full array with all valid items.
*
* Compare to searchColumn() this function return will return all found results.
* Compared to `searchColumn()` this function return will return all found results.
*
* > This function is not casesensitive, which means FOO will match Foo, foo and FOO
* > This function is not case-sensitive, which means `FOO` will match `Foo`, `foo` and `FOO`.
*
* ```php
* $array = [
Expand Down Expand Up @@ -244,9 +244,9 @@ public static function searchColumns(array $array, $column, $search)
}

/**
* Generate an Array from a Rang with an appending optional Text.
* Generate an array from a range with an appending optional text.
*
* This is commonly used when generate dropDowns in forms to select a number of something.
* This is commonly used when generate dropdowns in forms to select a number of something.
*
* When $text is an array, the first key is the singular value to use, the second is the pluralized value.
*
Expand All @@ -262,7 +262,7 @@ public static function searchColumns(array $array, $column, $search)
* // array (1 => "1 ticket", 2 => "2 tickets", 3 => "3 tickets")
* ```
*
* In php range() function is used to generate the array range.
* PHP's `range()` function is used to generate the array range.
*
* @param string|integer $from The range starts from
* @param string|integer $to The range ends
Expand Down
20 changes: 10 additions & 10 deletions src/helpers/ExportHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@
class ExportHelper
{
/**
* Export an Array or QueryInterface instance into a CSV formated string.
* Export an array or QueryInterface instance into a CSV-formatted string.
*
* @param array|QueryInterface $input The data to export into a csv
* @param array $keys Defines which keys should be packed into the generated CSV. The defined keys does not change the sort behavior of the generated csv.
* @param boolean $header Whether the column name should be set as header inside the csv or not.
* @param array|QueryInterface $input The data to export into a CSV
* @param array $keys Defines which keys should be packed into the generated CSV. The defined keys does not change the sort behavior of the generated CSV.
* @param boolean $header Whether the column name should be set as header inside the CSV or not.
* @param array $options Options
* + `sort`: boolean, whether they row should be sorted by its keys, default is true.
* + `sort`: boolean, whether they row should be sorted by its keys, default is `true`.
* @return string The generated CSV as string.
*/
public static function csv($input, array $keys = [], $header = true, array $options = [])
Expand All @@ -34,13 +34,13 @@ public static function csv($input, array $keys = [], $header = true, array $opti
}

/**
* Export an Array or QueryInterface instance into a Excel formatted string.
* Export an array or QueryInterface instance into an Excel-formatted string.
*
* @param array|QueryInterface $input
* @param array $keys Defines which keys should be packed into the generated xlsx. The defined keys does not change the sort behavior of the generated xls.
* @param array $keys Defines which keys should be packed into the generated XLSX. The defined keys does not change the sort behavior of the generated XLS.
* @param bool $header
* @param array $options Options
* + `sort`: boolean, whether they row should be sorted by its keys, default is true.
* + `sort`: boolean, whether they row should be sorted by its keys, default is `true`.
* @return mixed
* @throws Exception
*/
Expand Down Expand Up @@ -78,7 +78,7 @@ protected static function transformInput($input)
* @param array $keys
* @param bool $generateHeader
* @param array $options Options
* + `sort`: boolean, whether they row should be sorted by its keys, default is true.
* + `sort`: boolean, whether they row should be sorted by its keys, default is `true`.
* @return array
* @throws Exception
*/
Expand Down Expand Up @@ -185,7 +185,7 @@ protected static function generateRow(array $row, $delimiter, $enclose)
}

/**
* Sanitize Certain Values to increase security from user generated output.
* Sanitize certain values to increase security from user generated output.
*
* @param string $value
* @return string
Expand Down
42 changes: 21 additions & 21 deletions src/helpers/FileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
/**
* Helper methods when dealing with Files.
*
* Extends the {{yii\helpers\FileHelper}} class by some usefull functions like:
* Extends the {{yii\helpers\FileHelper}} class by some useful functions like:
*
* + {{luya\yii\helpers\FileHelper::humanReadableFilesize()}}
* + {{luya\yii\helpers\FileHelper::ensureExtension()}}
Expand All @@ -23,7 +23,7 @@
class FileHelper extends \yii\helpers\BaseFileHelper
{
/**
* Generate a human readable size informations from provided Byte/s size
* Generate a human readable size informations from provided Byte/s size.
*
* @param integer $size The size to convert in Byte
* @return string The readable size definition
Expand Down Expand Up @@ -60,12 +60,12 @@ public static function ensureExtension($file, $extension)
/**
* Provide class informations from a file path or file content.
*
* This is used when working with file paths from composer, in order to detect class and namespace from a given file.
* This is used when working with file paths from Composer, in order to detect class and namespace from a given file.
*
* @param string $file The file path to the class into order to get infos from, could also be the content directly from a given file.
* @return array If the given filepath is a file, it will return an array with the keys:
* + namespace: the namespace of the file, if false no namespace could have been determined.
* + class: the class name of the file, if false no class could have been determined.
* @return array If the given file path is a file, it will return an array with the keys:
* + `namespace`: the namespace of the file, `false` if no namespace could have been determined.
* + `class`: the class name of the file, `false` if no class could have been determined.
*/
public static function classInfo($file)
{
Expand All @@ -87,9 +87,9 @@ public static function classInfo($file)
}

/**
* Tokenize the php code from a given class in in order to determine the class name.
* Tokenize the PHP code from a given class in in order to determine the class name.
*
* @param string $phpCode The php code to tokenize and find the clas name from
* @param string $phpCode The PHP code to tokenize and find the class name from
* @return array
*/
private static function classNameByTokens($phpCode)
Expand All @@ -110,10 +110,10 @@ private static function classNameByTokens($phpCode)
* Create a unique hash name from a given file.
*
* Warning
* Because PHP's integer type is signed many crc32 checksums will result in negative integers on 32bit platforms. On 64bit installations all crc32() results will be positive integers though.
* So you need to use the "%u" formatter of sprintf() or printf() to get the string representation of the unsigned crc32() checksum in decimal format.
* Because PHP's integer type is signed many `crc32()` checksums will result in negative integers on 32-bit platforms. On 64-bit installations all `crc32()` results will be positive integers though.
* So you need to use the `%u` formatter of `sprintf()` or `printf()` to get the string representation of the unsigned `crc32()` checksum in decimal format.
*
* @param string $fileName The file name which should be hashed
* @param string $fileName The file name which should be hashed.
* @return string
*/
public static function hashName($fileName)
Expand All @@ -129,7 +129,7 @@ public static function hashName($fileName)
*/
public static function getFileInfo($sourceFile)
{
// pathinfo always returns an array event the path does not exists
// pathinfo() always returns an array event the path does not exists
$path = pathinfo($sourceFile);

return (object) [
Expand All @@ -141,22 +141,22 @@ public static function getFileInfo($sourceFile)
}

/**
* Generate a md5 hash of a file. This is eqauls to `md5sum` command
* Generate a MD5 hash of a file. This is equal to `md5sum` command.
*
* @param string $sourceFile The path to the file
* @return false|string Returns false or the md5 hash of this file
* @return false|string Returns false or the MD5 hash of this file
*/
public static function md5sum($sourceFile)
{
return file_exists($sourceFile) ? hash_file('md5', $sourceFile) : false;
}

/**
* Basic helper method to write files with exception capture. The fileName will auto wrapped
* trough the Yii::getAlias function.
* Basic helper method to write files with exception capture. The filename will auto-wrapped
* through the `Yii::getAlias()` function.
*
* @param string $fileName The path to the file with file name
* @param string $content The content to store in this File
* @param string $fileName The path to the file with filename
* @param string $content The content to store in this file
* @return boolean
*/
public static function writeFile($fileName, $content)
Expand All @@ -174,8 +174,8 @@ public static function writeFile($fileName, $content)
}

/**
* Basic helper to retreive the content of a file and catched exception. The filename
* will auto alias encode by Yii::getAlias function.
* Basic helper to retrieve the content of a file and catched exception. The filename
* will auto-alias encoded by `Yii::getAlias()` function.
*
* @param string $fileName The path to the file to get the content
* @return string|boolean
Expand Down Expand Up @@ -215,7 +215,7 @@ public static function unlink($file)
}
}

// try to use realpath
// try to use realpath()
if (realpath($file) && realpath($file) !== $file) {
if (@unlink(realpath($file))) {
return true;
Expand Down
22 changes: 11 additions & 11 deletions src/helpers/ImportHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,25 @@ class ImportHelper
/**
* Import a CSV from a string or filename and return array.
*
* The filename can be either a resource from fopen() or a string containing the csv data. Filenames will be wrapped trough {{Yii::getAlias()}} method.
* The filename can be either a resource from `fopen()` or a string containing the CSV data. Filenames will be wrapped through {{`Yii::getAlias()`}} method.
*
* @param string $filename Can be either a filename which is parsed by {{luya\yii\helpers\FileHelper::getFileContent()}} or a string with the contained csv data.
* @param array $options Provide options to the csv
* + removeHeader: boolean, Whether the import csv contains a header in the first row to skip or not. Default value is false.
* + delimiter: string, The delimiter which is used to explode the columns. Default value is `,`.
* + enclosure: string, The encloser which is used betweend the columns. Default value is `"`.
* + fields: array, An array with fielnames (based on the array header if any, or position) which should be parsed into the final export.
* @param string $filename Can be either a filename which is parsed by {{luya\yii\helpers\FileHelper::getFileContent()}} or a string with the contained CSV data.
* @param array $options Provide options to the CSV
* + `removeHeader`: boolean, Whether the import CSV contains a header in the first row to skip or not. Default value is false.
* + `delimiter`: string, The delimiter which is used to explode the columns. Default value is `,`.
* + `enclosure`: string, The enclosure which is used between the columns. Default value is `"`.
* + `fields`: array, An array with filenames (based on the array header if any, or position) which should be parsed into the final export.
* ```php
* 'fields' => ['firstname', 'lastname'] // will only parse those fields based on table header (row 0)
* 'fields' => [0,1,3] // will only parse fields by those positions if no table header is present. Positions starts at 0
* 'fields' => [0,1,3] // will only parse fields by those positions if no table header is present. Positions starts at 0.
* ```
* @return array an array with the csv data.
* @return array an array with the CSV data.
*/
public static function csv($filename, array $options = [])
{
$filename = Yii::getAlias($filename);

// check if a given file name is provided or a csv based on the content
// check if a given file name is provided or a CSV based on the content
if (FileHelper::getFileInfo($filename)->extension) {
$resource = fopen($filename, 'r');
} else {
Expand Down Expand Up @@ -66,7 +66,7 @@ public static function csv($filename, array $options = [])
unset($filteredData);
}

// if the option to remove a header is provide. remove the first key and reset and array keys
// if the option to remove a header is provided, remove the first key and re-set array keys
if (ArrayHelper::getValue($options, 'removeHeader', false)) {
unset($data[0]);
$data = array_values($data);
Expand Down
6 changes: 3 additions & 3 deletions src/helpers/Inflector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use yii\helpers\BaseInflector;

/**
* Helper methods which can be used for string transformations
* Helper methods which can be used for String transformations
*
* Extends the {{yii\helpers\BaseInflector}} class by:
*
Expand All @@ -20,7 +20,7 @@ class Inflector extends BaseInflector
* From yii/helpers/BaseInflector:
*
* Returns a string with all spaces converted to given replacement,
* non word characters removed and the rest of characters transliterated.
* non-word characters removed and the rest of characters transliterated.
*
* If intl extension isn't available uses fallback that converts latin characters only
* and removes the rest. You may customize characters map via $transliteration property
Expand All @@ -29,7 +29,7 @@ class Inflector extends BaseInflector
* @param string $string An arbitrary string to convert
* @param string $replacement The replacement to use for spaces
* @param bool $lowercase whether to return the string in lowercase or not. Defaults to `true`.
* @param bool $transliterate whether to use a transliteration transformation or not. Defaults to `true` (=BaseInflector implementation)
* @param bool $transliterate whether to use a transliteration transformation or not. Defaults to `true` (=`BaseInflector` implementation)
* @return string The converted string.
*/
public static function slug($string, $replacement = '-', $lowercase = true, $transliterate = true)
Expand Down
Loading
Loading