File: check-valid-function.php

package info (click to toggle)
php-doc 20241205~git.dfcbb86%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 70,956 kB
  • sloc: xml: 968,269; php: 23,883; javascript: 671; sh: 177; makefile: 37
file content (108 lines) | stat: -rw-r--r-- 3,875 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
/*
  +----------------------------------------------------------------------+
  | Copyright (c) 1997-2023 The PHP Group                                |
  +----------------------------------------------------------------------+
  | This source file is subject to version 3.01 of the PHP license,      |
  | that is bundled with this package in the file LICENSE, and is        |
  | available through the world-wide-web at the following url:           |
  | https://www.php.net/license/3_01.txt.                                |
  | If you did not receive a copy of the PHP license and are unable to   |
  | obtain it through the world-wide-web, please send a note to          |
  | license@php.net, so we can mail you a copy immediately.              |
  +----------------------------------------------------------------------+
  | Authors:    Dave Barr <dave@php.net>                                 |
  |             Gina Peter Banyard <girgias@php.net>                     |
  +----------------------------------------------------------------------+
  | Description: This file parses the manual and outputs all erroneous   |
  |              <function> tag usage.                                   |
  +----------------------------------------------------------------------+

*/

/** TODO
 * - Handle Class and methods
 */

/* Path to the root of EN extension reference tree */
$doc_en_root = dirname(__DIR__, 3) . '/en/reference';

$total = 0;

/* make a function list from files in the functions/ directories */
function make_func_list(string $lang_doc_root): array
{
    /* initialize array and declare some language constructs */
    $functions = [
        'include' => true,
        'include_once' => true,
        'require' => true,
        'require_once' => true,
        'return' => true,
    ];

    foreach (new DirectoryIterator($lang_doc_root) as $extensions) {
        if ($extensions->isDot() || !$extensions->isDir() || !$extensions->isReadable()) {
            continue;
        }

        foreach (new DirectoryIterator($extensions->getPathname()) as $extension) {
            if ($extension->isDot() || !$extension->isDir() || !$extension->isReadable()) {
                continue;
            }
            if ($extension->getFilename() !== 'functions') {
                continue;
            }

            foreach (new DirectoryIterator($extension->getPathname()) as $file) {
                if ($file->isDot() || !$file->isReadable()) {
                    continue;
                }
                $function = str_replace(['-', '.'], '_', $file->getBasename('.xml'));
                $functions[$function] = true;
            }
        }
    }

    return $functions;
}

echo "Building a list of functions...\n";
$functions =  make_func_list($doc_en_root);

echo 'List complete. ' . count($functions) . " functions.\n";

echo "Checking the manual for <function> tags that contain invalid functions...\n";
foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($doc_en_root)) as $file) {
    if ($file->isDir() || !$file->isReadable()) {
        continue;
    }

    $name = $file->getBasename();
    $path = $file->getPathname();
    $contents = file_get_contents($path);

    if ($contents == '') {
        continue;
    }

    if (preg_match_all('|<function>(.*?)</function>|s', $contents, $m)
        && is_array($m)
        && is_array($m[1]))
    {
        foreach ($m[1] as $func) {
            //$func = strtolower(str_replace(array('::', '->'), '_', trim($func)));
            $func = trim($func);

            if (!\array_key_exists($func, $functions)) {
                $total++;
                $fileout = substr($file, strlen($doc_en_root) + 1);

                printf("%-60.60s  <function>$func</function>\n", $fileout);
            }
        }
    }
}
echo "Found $total occurrences.\n";

exit((bool) $total);