Skip to content

Commit

Permalink
Add PHPDoc
Browse files Browse the repository at this point in the history
  • Loading branch information
alphayax committed Jun 18, 2016
1 parent ad6ef12 commit b18661b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
4 changes: 1 addition & 3 deletions src/GetOpt.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
namespace alphayax\utils\cli;
use alphayax\utils\cli\exception\MissingArgException;
use alphayax\utils\cli\exception\MissingArgValueException;
use alphayax\utils\cli\model\Help;
use alphayax\utils\cli\model\Option;
use alphayax\utils\cli\model\OptionList;
Expand Down Expand Up @@ -97,9 +98,6 @@ public function parse(){
$exception->setRequiredArgs( $requiredOpts);
throw $exception;
}

/// If provided fields needs a non provided value, throw an exception
// TODO : MissingArgValueException
}

/**
Expand Down
25 changes: 25 additions & 0 deletions src/model/OptionList.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,17 @@ class OptionList implements \Iterator {
protected $iteratorIndex = 0;

/**
* Add an option to the list
* @param \alphayax\utils\cli\model\Option $option
*/
public function add( Option $option) {
$this->options[] = $option;
}

/**
* Return an array with longs option for get_opt
* @return array
*/
public function serializeLongOpts() {
$longOpts = [];
foreach( $this->options as $option){
Expand All @@ -31,6 +36,10 @@ public function serializeLongOpts() {
return $longOpts;
}

/**
* Return a serialized string with short options for get_opt
* @return string
*/
public function serializeShortOpts() {
$letters = '';
foreach( $this->options as $option){
Expand All @@ -42,6 +51,10 @@ public function serializeShortOpts() {
return $letters;
}

/**
* Get all options
* @return \alphayax\utils\cli\model\Option[]
*/
public function getAll() {
$options = $this->options;
usort( $options, function( Option $optionA, Option $optionB){
Expand All @@ -52,6 +65,10 @@ public function getAll() {
return $options;
}

/**
* Get required options
* @return array
*/
public function getRequiredOpts() {
$requiredOpts = [];
foreach( $this->options as $option){
Expand All @@ -62,6 +79,10 @@ public function getRequiredOpts() {
return $requiredOpts;
}

/**
* Get the pad of long args for display in help
* @return int
*/
public function getLongPad() {
$pad = 1;
foreach( $this->options as $option){
Expand All @@ -76,6 +97,10 @@ public function getLongPad() {
return $pad + 2; // +2 is for double hyphen (--)
}

/**
* Get the pad of short args for display in help
* @return int
*/
public function getShortPad() {
$pad = 1;
foreach( $this->options as $option){
Expand Down

0 comments on commit b18661b

Please sign in to comment.