Yioop_V9.5_Source_Code_Documentation

CodeTool.php

SeekQuarry/Yioop -- Open Source Pure PHP Search Engine, Crawler, and Indexer

Copyright (C) 2009 - 2023 Chris Pollett chris@pollett.org

LICENSE:

This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see https://www.gnu.org/licenses/.

END LICENSE

Tool used to help coding with Yioop. Has commands to update copyright info, clean trailing spaces, find long lines, and do global file searches and replaces.

Tags
author

Chris Pollett chris@pollett.org

license

https://www.gnu.org/licenses/ GPL3

link
https://www.seekquarry.com/
copyright

2009 - 2023

filesource

Table of Contents

clean()  : bool
Used to clean trailing whitespace from files in a folder or just from a file given in the command line. If also removes final ?> characters to make php files conform with suggested coding guidelines. Similarly, adds a space between if, for, foreach, etc and ( if not present to make match PHP coding guidelines
copyright()  : bool
Updates the copyright info (assuming in Yioop docs format) on files in supplied sub-folder/file. That is, it changes strings matching /2009 - \d\d\d\d/ to 2009 - current_year in those files/file.
longlines()  : bool
Search and echos line numbers and lines for lines of length greater than 80 characters in files in supplied sub-folder/file,
needsdocs()  : bool
Search and echos line numbers and lines for lines of length greater than 80 characters in files in supplied sub-folder/file,
replace()  : bool
Performs a search and replace for given pattern in files in supplied sub-folder/file
search()  : bool
Performs a search for given pattern in files in supplied sub-folder/file
unit()  : bool
Used to run or list Yioop unit tests given in $args
changeCopyrightFile()  : mixed
Callback function applied to each file in the directory being traversed by @see copyright(). It checks if the files is of the extension of a code file and if so trims whitespace from its lines and then updates the lines of the form 2009 - \d\d\d\d to the supplied copyright year
cleanLinesFile()  : mixed
Callback function applied to each file in the directory being traversed by @see clean().
searchFile()  : mixed
Callback function applied to each file in the directory being traversed by @see search(). Searches $filename matching $pattern and outputs line numbers and lines
replaceFile()  : mixed
Callback function applied to each file in the directory being traversed by @see replace(). Searches $filename matching $pattern. Depending on $mode ($arg[2] as described in replace()), it outputs and replaces with $replace
mapPath()  : mixed
Applies the function $callback to each file in $path
excludedPath()  : bool
Checks if $path is amongst a list of paths which should be ignored

Functions

clean()

Used to clean trailing whitespace from files in a folder or just from a file given in the command line. If also removes final ?> characters to make php files conform with suggested coding guidelines. Similarly, adds a space between if, for, foreach, etc and ( if not present to make match PHP coding guidelines

clean(array<string|int, mixed> $args) : bool
Parameters
$args : array<string|int, mixed>

$args[0] contains path to sub-folder/file

Return values
bool

$no_instructions false if should output CodeTool.php instructions

Updates the copyright info (assuming in Yioop docs format) on files in supplied sub-folder/file. That is, it changes strings matching /2009 - \d\d\d\d/ to 2009 - current_year in those files/file.

copyright(array<string|int, mixed> $args) : bool
Parameters
$args : array<string|int, mixed>

$args[0] contains path to sub-folder/file

Return values
bool

$no_instructions false if should output CodeTool.php instructions

longlines()

Search and echos line numbers and lines for lines of length greater than 80 characters in files in supplied sub-folder/file,

longlines(array<string|int, mixed> $args) : bool
Parameters
$args : array<string|int, mixed>

$args[0] contains path to sub-folder/file

Return values
bool

$no_instructions false if should output CodeTool.php instructions

needsdocs()

Search and echos line numbers and lines for lines of length greater than 80 characters in files in supplied sub-folder/file,

needsdocs(array<string|int, mixed> $args) : bool
Parameters
$args : array<string|int, mixed>

$args[0] contains path to sub-folder/file

Return values
bool

$no_instructions false if should output CodeTool.php instructions

replace()

Performs a search and replace for given pattern in files in supplied sub-folder/file

replace(array<string|int, mixed> $args) : bool
Parameters
$args : array<string|int, mixed>

$args[0] contains path to sub-folder/file, $args[1] contains the regex searching for, $args[2] contains what it should be replaced with, $args[3] (defaults to effect) controls the mode of operation. One of "effect", "change", or "interactive". effect shows line number and lines matching pattern, but commits no changes; interactive for each match, prompts user if should do the change, change does a global search and replace without output

Return values
bool

$no_instructions false if should output CodeTool.php instructions

Performs a search for given pattern in files in supplied sub-folder/file

search(array<string|int, mixed> $args) : bool
Parameters
$args : array<string|int, mixed>

$args[0] contains path to sub-folder/file, $args[1] contains the regex searching for

Return values
bool

$no_instructions false if should output CodeTool.php instructions

unit()

Used to run or list Yioop unit tests given in $args

unit(array<string|int, mixed> $args) : bool
Parameters
$args : array<string|int, mixed>
  • if empty run all tests, if $args[0] == 'list' then list available test. If $args[0] == name_of_particular then run just that test. If $args[1] == name_of_particular case, then just run that test case of the particular test.
Return values
bool

whether $args made sense so could process

changeCopyrightFile()

Callback function applied to each file in the directory being traversed by @see copyright(). It checks if the files is of the extension of a code file and if so trims whitespace from its lines and then updates the lines of the form 2009 - \d\d\d\d to the supplied copyright year

changeCopyrightFile(string $filename[, mixed $set_year = false ]) : mixed
Parameters
$filename : string

name of file to check for copyright lines and updated

$set_year : mixed = false

if false then set the end of the copyright period to the current year, otherwise, if an int sets it to the value of the int

Return values
mixed

cleanLinesFile()

Callback function applied to each file in the directory being traversed by @see clean().

cleanLinesFile(string $filename) : mixed
Parameters
$filename : string

name of file to clean lines for

Return values
mixed

searchFile()

Callback function applied to each file in the directory being traversed by @see search(). Searches $filename matching $pattern and outputs line numbers and lines

searchFile(string $filename[, mixed $set_pattern = false ]) : mixed
Parameters
$filename : string

name of file to search in

$set_pattern : mixed = false

if not false, then sets $set_pattern in $pattern to initialize the callback on subsequent calls. $pattern here is the search pattern

Return values
mixed

replaceFile()

Callback function applied to each file in the directory being traversed by @see replace(). Searches $filename matching $pattern. Depending on $mode ($arg[2] as described in replace()), it outputs and replaces with $replace

replaceFile(string $filename[, mixed $set_pattern = false ][, mixed $set_replace = false ][, mixed $set_mode = false ]) : mixed
Parameters
$filename : string

name of file to search and replace in

$set_pattern : mixed = false

if not false, then sets $set_pattern in $pattern to initialize the callback on subsequent calls. $pattern here is the search pattern

$set_replace : mixed = false

if not false, then sets $set_replace in $replace to initialize the callback on subsequent calls.

$set_mode : mixed = false

if not false, then sets $set_mode in $mode to initialize the callback on subsequent calls.

Return values
mixed

mapPath()

Applies the function $callback to each file in $path

mapPath(string $path, string $callback) : mixed
Parameters
$path : string

to apply map $callback to

$callback : string

function name to call with filename of each file in path

Return values
mixed

excludedPath()

Checks if $path is amongst a list of paths which should be ignored

excludedPath( $path) : bool
Parameters
$path :

a directory path

Return values
bool

whether or not it should be ignored (true == ignore)

Search results