Skip to content

Commit df68dbf

Browse files
authored
Merge pull request #20 from hbugdoll/typo-fixes
Fixed typos and more
2 parents df002ac + 457e9e3 commit df68dbf

16 files changed

+173
-174
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ A set of helper classes for the Yii Framework which are used as LUYA Helpers.
99

1010
## Installation
1111

12-
In order to install the LUYA Yii Framework Helpers use composer:
12+
In order to install the LUYA Yii Framework Helpers use Composer:
1313

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

2222
+ ArrayHelper - Working with Arrays
23-
+ ExportHelper - Export Data into a given Format (f.e. CSV, XLS)
23+
+ ExportHelper - Export Data into a given Format (e.g. CSV, XLS)
2424
+ ImportHelper - Import Data
2525
+ FileHelper - Working with Filesystem
26-
+ Json = Working with Json Data
26+
+ Json = Working with JSON Data
2727
+ RestHelper - Yii Framework REST API Output
2828
+ StringHelper - Working with Strings
2929
+ ZipHelper - Create ZIP Archives

src/helpers/ArrayHelper.php

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
/**
88
* Helper methods when dealing with Arrays.
99
*
10-
* Extends the {{yii\helpers\ArrayHelper}} class by some usefull functions like:
10+
* Extends the {{yii\helpers\ArrayHelper}} class by some useful functions like:
1111
*
1212
* + {{luya\yii\helpers\ArrayHelper::toObject()}}
1313
* + {{luya\yii\helpers\ArrayHelper::arrayUnshiftAssoc()}}
@@ -39,9 +39,9 @@ public static function toObject(array $array)
3939
}
4040

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

76-
// the later overrides the former
76+
// the latter overrides the former
7777
return array_replace($data, $clean);
7878
}
7979

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

122122
/**
123-
* Search trough all keys inside of an array, any occurence will return the rest of the array.
123+
* Search through all keys inside of an array, any occurrence will return the rest of the array.
124124
*
125125
* ```php
126126
* $data = [
@@ -137,7 +137,7 @@ public static function typeCast(array $array)
137137
* ];
138138
* ```
139139
*
140-
* Searching for the string `Bar` would return the the orignal array is bar would be found in both.
140+
* Searching for the string `Bar` would return the original array if bar would be found in both.
141141
*
142142
* In order to search only in certain keys defined $keys attribute:
143143
*
@@ -149,7 +149,7 @@ public static function typeCast(array $array)
149149
*
150150
* @param array $array The multidimensional array keys.
151151
* @param string $searchText The text you where search inside the rows.
152-
* @param boolean $sensitive Whether to use strict sensitive search (true) or case insenstivie search (false).
152+
* @param boolean $sensitive Whether to use strict sensitive search (`true`) or case insensitive search (`false`).
153153
* @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.
154154
* @return array The modified array depending on the search result hits.
155155
*/
@@ -176,9 +176,9 @@ public static function search(array $array, $searchText, $sensitive = false, arr
176176
}
177177

178178
/**
179-
* Search for a Column Value inside a Multidimension array and return the array with the found key.
179+
* Search for a column value inside a multidimensional array and return the array with the found key.
180180
*
181-
* Compare to searchColumns() this function return will return the first found result.
181+
* Compared to `searchColumns()` this function return will return the first found result.
182182
*
183183
* ```php
184184
* $array = [
@@ -192,7 +192,7 @@ public static function search(array $array, $searchText, $sensitive = false, arr
192192
* // array ('name' => 'nadar', 'userId' => 2);
193193
* ```
194194
*
195-
* > This will not work with assoc keys
195+
* > This will not work with associative keys
196196
*
197197
* @param array $array The array with the multimensional array values.
198198
* @param string $column The column to lookup and compare with the $search string.
@@ -210,9 +210,9 @@ public static function searchColumn(array $array, $column, $search)
210210
/**
211211
* Search for columns with the given search value, returns the full array with all valid items.
212212
*
213-
* Compare to searchColumn() this function return will return all found results.
213+
* Compared to `searchColumn()` this function return will return all found results.
214214
*
215-
* > This function is not casesensitive, which means FOO will match Foo, foo and FOO
215+
* > This function is not case-sensitive, which means `FOO` will match `Foo`, `foo` and `FOO`.
216216
*
217217
* ```php
218218
* $array = [
@@ -244,9 +244,9 @@ public static function searchColumns(array $array, $column, $search)
244244
}
245245

246246
/**
247-
* Generate an Array from a Rang with an appending optional Text.
247+
* Generate an array from a range with an appending optional text.
248248
*
249-
* This is commonly used when generate dropDowns in forms to select a number of something.
249+
* This is commonly used when generate dropdowns in forms to select a number of something.
250250
*
251251
* When $text is an array, the first key is the singular value to use, the second is the pluralized value.
252252
*
@@ -262,7 +262,7 @@ public static function searchColumns(array $array, $column, $search)
262262
* // array (1 => "1 ticket", 2 => "2 tickets", 3 => "3 tickets")
263263
* ```
264264
*
265-
* In php range() function is used to generate the array range.
265+
* PHP's `range()` function is used to generate the array range.
266266
*
267267
* @param string|integer $from The range starts from
268268
* @param string|integer $to The range ends

src/helpers/ExportHelper.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@
1515
class ExportHelper
1616
{
1717
/**
18-
* Export an Array or QueryInterface instance into a CSV formated string.
18+
* Export an array or QueryInterface instance into a CSV-formatted string.
1919
*
20-
* @param array|QueryInterface $input The data to export into a csv
21-
* @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.
22-
* @param boolean $header Whether the column name should be set as header inside the csv or not.
20+
* @param array|QueryInterface $input The data to export into a CSV
21+
* @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.
22+
* @param boolean $header Whether the column name should be set as header inside the CSV or not.
2323
* @param array $options Options
24-
* + `sort`: boolean, whether they row should be sorted by its keys, default is true.
24+
* + `sort`: boolean, whether they row should be sorted by its keys, default is `true`.
2525
* @return string The generated CSV as string.
2626
*/
2727
public static function csv($input, array $keys = [], $header = true, array $options = [])
@@ -34,13 +34,13 @@ public static function csv($input, array $keys = [], $header = true, array $opti
3434
}
3535

3636
/**
37-
* Export an Array or QueryInterface instance into a Excel formatted string.
37+
* Export an array or QueryInterface instance into an Excel-formatted string.
3838
*
3939
* @param array|QueryInterface $input
40-
* @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.
40+
* @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.
4141
* @param bool $header
4242
* @param array $options Options
43-
* + `sort`: boolean, whether they row should be sorted by its keys, default is true.
43+
* + `sort`: boolean, whether they row should be sorted by its keys, default is `true`.
4444
* @return mixed
4545
* @throws Exception
4646
*/
@@ -78,7 +78,7 @@ protected static function transformInput($input)
7878
* @param array $keys
7979
* @param bool $generateHeader
8080
* @param array $options Options
81-
* + `sort`: boolean, whether they row should be sorted by its keys, default is true.
81+
* + `sort`: boolean, whether they row should be sorted by its keys, default is `true`.
8282
* @return array
8383
* @throws Exception
8484
*/
@@ -185,7 +185,7 @@ protected static function generateRow(array $row, $delimiter, $enclose)
185185
}
186186

187187
/**
188-
* Sanitize Certain Values to increase security from user generated output.
188+
* Sanitize certain values to increase security from user generated output.
189189
*
190190
* @param string $value
191191
* @return string

src/helpers/FileHelper.php

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
/**
99
* Helper methods when dealing with Files.
1010
*
11-
* Extends the {{yii\helpers\FileHelper}} class by some usefull functions like:
11+
* Extends the {{yii\helpers\FileHelper}} class by some useful functions like:
1212
*
1313
* + {{luya\yii\helpers\FileHelper::humanReadableFilesize()}}
1414
* + {{luya\yii\helpers\FileHelper::ensureExtension()}}
@@ -23,7 +23,7 @@
2323
class FileHelper extends \yii\helpers\BaseFileHelper
2424
{
2525
/**
26-
* Generate a human readable size informations from provided Byte/s size
26+
* Generate a human readable size informations from provided Byte/s size.
2727
*
2828
* @param integer $size The size to convert in Byte
2929
* @return string The readable size definition
@@ -60,12 +60,12 @@ public static function ensureExtension($file, $extension)
6060
/**
6161
* Provide class informations from a file path or file content.
6262
*
63-
* This is used when working with file paths from composer, in order to detect class and namespace from a given file.
63+
* This is used when working with file paths from Composer, in order to detect class and namespace from a given file.
6464
*
6565
* @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.
66-
* @return array If the given filepath is a file, it will return an array with the keys:
67-
* + namespace: the namespace of the file, if false no namespace could have been determined.
68-
* + class: the class name of the file, if false no class could have been determined.
66+
* @return array If the given file path is a file, it will return an array with the keys:
67+
* + `namespace`: the namespace of the file, `false` if no namespace could have been determined.
68+
* + `class`: the class name of the file, `false` if no class could have been determined.
6969
*/
7070
public static function classInfo($file)
7171
{
@@ -87,9 +87,9 @@ public static function classInfo($file)
8787
}
8888

8989
/**
90-
* Tokenize the php code from a given class in in order to determine the class name.
90+
* Tokenize the PHP code from a given class in in order to determine the class name.
9191
*
92-
* @param string $phpCode The php code to tokenize and find the clas name from
92+
* @param string $phpCode The PHP code to tokenize and find the class name from
9393
* @return array
9494
*/
9595
private static function classNameByTokens($phpCode)
@@ -110,10 +110,10 @@ private static function classNameByTokens($phpCode)
110110
* Create a unique hash name from a given file.
111111
*
112112
* Warning
113-
* 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.
114-
* 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.
113+
* 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.
114+
* 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.
115115
*
116-
* @param string $fileName The file name which should be hashed
116+
* @param string $fileName The file name which should be hashed.
117117
* @return string
118118
*/
119119
public static function hashName($fileName)
@@ -129,7 +129,7 @@ public static function hashName($fileName)
129129
*/
130130
public static function getFileInfo($sourceFile)
131131
{
132-
// pathinfo always returns an array event the path does not exists
132+
// pathinfo() always returns an array event the path does not exists
133133
$path = pathinfo($sourceFile);
134134

135135
return (object) [
@@ -141,22 +141,22 @@ public static function getFileInfo($sourceFile)
141141
}
142142

143143
/**
144-
* Generate a md5 hash of a file. This is eqauls to `md5sum` command
144+
* Generate a MD5 hash of a file. This is equal to `md5sum` command.
145145
*
146146
* @param string $sourceFile The path to the file
147-
* @return false|string Returns false or the md5 hash of this file
147+
* @return false|string Returns false or the MD5 hash of this file
148148
*/
149149
public static function md5sum($sourceFile)
150150
{
151151
return file_exists($sourceFile) ? hash_file('md5', $sourceFile) : false;
152152
}
153153

154154
/**
155-
* Basic helper method to write files with exception capture. The fileName will auto wrapped
156-
* trough the Yii::getAlias function.
155+
* Basic helper method to write files with exception capture. The filename will auto-wrapped
156+
* through the `Yii::getAlias()` function.
157157
*
158-
* @param string $fileName The path to the file with file name
159-
* @param string $content The content to store in this File
158+
* @param string $fileName The path to the file with filename
159+
* @param string $content The content to store in this file
160160
* @return boolean
161161
*/
162162
public static function writeFile($fileName, $content)
@@ -174,8 +174,8 @@ public static function writeFile($fileName, $content)
174174
}
175175

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

218-
// try to use realpath
218+
// try to use realpath()
219219
if (realpath($file) && realpath($file) !== $file) {
220220
if (@unlink(realpath($file))) {
221221
return true;

src/helpers/ImportHelper.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ class ImportHelper
1515
/**
1616
* Import a CSV from a string or filename and return array.
1717
*
18-
* The filename can be either a resource from fopen() or a string containing the csv data. Filenames will be wrapped trough {{Yii::getAlias()}} method.
18+
* The filename can be either a resource from `fopen()` or a string containing the CSV data. Filenames will be wrapped through {{`Yii::getAlias()`}} method.
1919
*
20-
* @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.
21-
* @param array $options Provide options to the csv
22-
* + removeHeader: boolean, Whether the import csv contains a header in the first row to skip or not. Default value is false.
23-
* + delimiter: string, The delimiter which is used to explode the columns. Default value is `,`.
24-
* + enclosure: string, The encloser which is used betweend the columns. Default value is `"`.
25-
* + fields: array, An array with fielnames (based on the array header if any, or position) which should be parsed into the final export.
20+
* @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.
21+
* @param array $options Provide options to the CSV
22+
* + `removeHeader`: boolean, Whether the import CSV contains a header in the first row to skip or not. Default value is false.
23+
* + `delimiter`: string, The delimiter which is used to explode the columns. Default value is `,`.
24+
* + `enclosure`: string, The enclosure which is used between the columns. Default value is `"`.
25+
* + `fields`: array, An array with filenames (based on the array header if any, or position) which should be parsed into the final export.
2626
* ```php
2727
* 'fields' => ['firstname', 'lastname'] // will only parse those fields based on table header (row 0)
28-
* 'fields' => [0,1,3] // will only parse fields by those positions if no table header is present. Positions starts at 0
28+
* 'fields' => [0,1,3] // will only parse fields by those positions if no table header is present. Positions starts at 0.
2929
* ```
30-
* @return array an array with the csv data.
30+
* @return array an array with the CSV data.
3131
*/
3232
public static function csv($filename, array $options = [])
3333
{
3434
$filename = Yii::getAlias($filename);
3535

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

69-
// if the option to remove a header is provide. remove the first key and reset and array keys
69+
// if the option to remove a header is provided, remove the first key and re-set array keys
7070
if (ArrayHelper::getValue($options, 'removeHeader', false)) {
7171
unset($data[0]);
7272
$data = array_values($data);

src/helpers/Inflector.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use yii\helpers\BaseInflector;
66

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

0 commit comments

Comments
 (0)