Re: svn: /phpdoc/doc-base/trunk/scripts/ check-missing-initializers.php
| From: | Richard Quadling | Date: | Fri, 23 Oct 2009 10:45:00 +0000 |
| Subject: | Re: svn: /phpdoc/doc-base/trunk/scripts/ check-missing-initializers.php | ||
| References: | 1 | Groups: | php.doc.cvs |
| Request: | Send a blank email to doc-cvs+get-5202@lists.php.net to get a copy of this message | ||
2009/10/23 Philip Olson <philip@php.net>:
> philip Fri, 23 Oct 2009 00:50:03 +0000
>
> Revision:
> http://svn.php.net/viewvc?view=revision&revision=289869
>
> Log:
> Added a script that finds functions with optional parameters, but are missing the
> <initializer> tag
>
> Changed paths:
> A phpdoc/doc-base/trunk/scripts/check-missing-initializers.php
>
> Added: phpdoc/doc-base/trunk/scripts/check-missing-initializers.php
> ===================================================================
> --- phpdoc/doc-base/trunk/scripts/check-missing-initializers.php
> (rev 0)
> +++ phpdoc/doc-base/trunk/scripts/check-missing-initializers.php 2009-10-23 00:50:03
> UTC (rev 289869)
> @@ -0,0 +1,71 @@
> +<?php
> +/*
> +Introduction:
> + - This script checks for optional parameters that do not utilize the
> <initializer> tag.
> + - Pass in a path and it'll check it. The path might include all of phpdoc, or a
> simple extension
> +TODO:
> + - Have better output when using -o
> + - Determine what initializer values should be as some cases aren't clear
> +*/
> +
> +$opts = getopt('p:oh');
> +
> +if (isset($opts['h'])) {
> + usage();
> +}
> +if (empty($opts['p'])) {
> + echo "\nERROR:\n - A path is required\n";
> + usage();
> +}
> +if (!is_dir($opts['p'])) {
> + echo "\nERROR:\n - Please pass in a real directory, unlike this mysterious
> '$opts[p]'\n";
> + usage();
> +}
> +
> +$empty = array();
> +$count_total = 0;
> +$count_empty = 0;
> +
> +foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($opts['p']))
> as $file) {
> +
> + $filepath = $file->getPathname();
> + $filename = $file->getBasename();
> +
> + if (!$file->isFile() || pathinfo($filepath, PATHINFO_EXTENSION) !==
> 'xml') {
> + continue;
> + }
> +
> + $contents = file_get_contents($filepath);
> +
> + $matches = array();
> + preg_match_all('@<methodparam
> choice="opt"><type>(.*)</type><parameter>(.*)</parameter>(.*)</methodparam>@',
> $contents, $matches);
> +
> + // Check if any optional parameters exist
> + if (empty($matches)) {
> + continue;
> + }
> +
> + // Log optional parameters without default values
> + // We use the <initializer> DocBook tag for this task.
> + foreach ($matches[3] as $match) {
> + $count_total++;
> + if (empty($match) || (false === strpos($match,
> '<initializer>'))) {
> + $count_empty++;
> + $empty[$filepath] = $matches;
> + }
> + }
> +}
> +
> +// This output could be more useful
> +if (isset($opts['o'])) {
> + print_r($empty);
> +}
> +
> +print "Found $count_total optional parameters, and $count_empty are empty.\n";
> +
> +function usage() {
> + echo "\nUSAGE:\n";
> + echo "$ php {$_SERVER['SCRIPT_FILENAME']} -p
> /path/to/phpdoc/docs/to/check\n";
> + echo " Optional: Add -o to output the results.\n";
> + exit;
> +}
>
>
> Property changes on: phpdoc/doc-base/trunk/scripts/check-missing-initializers.php
> ___________________________________________________________________
> Added: svn:keywords
> + Id Rev Revision
> Added: svn:eol-style
> + native
>
>
> --
> PHP Documentation Commits Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
Just a thought but not all optional parameters have a discrete default value.
One that comes to mind from a recent bug/patch was substr.
The length parameter is optional.
The value though is dependent upon the length of the string.
What would be the best way to document this? Currently there is no
initializer for this parameter.
Is there anything wrong with ...
<initializer>length of $string</initializer>
I don't think we've used descriptions for defaults yet, so what do you
all think?
Regards,
Richard.
--
-----
Richard Quadling
"Standing on the shoulders of some very clever giants!"
EE : http://www.experts-exchange.com/M_248814.html
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
ZOPA : http://uk.zopa.com/member/RQuadling