code complexity & repetition analysis tool
1#!/usr/bin/env python3
2"""
3Example Python file with many lines of code
4Demonstrates LOC counting with comments and blank lines
5"""
6
7import sys
8import os
9from typing import List, Dict, Optional
10
11
12class DataProcessor:
13 """Process data with various transformations"""
14
15 def __init__(self, config: Dict):
16 self.config = config
17 self.data = []
18 self.results = {}
19
20 def load_data(self, filepath: str) -> bool:
21 """Load data from a file"""
22 try:
23 with open(filepath, 'r') as f:
24 self.data = [line.strip() for line in f]
25 return True
26 except FileNotFoundError:
27 print(f"File not found: {filepath}")
28 return False
29
30 def process(self) -> List[str]:
31 """Process the loaded data"""
32 results = []
33
34 for item in self.data:
35 # Skip empty lines
36 if not item:
37 continue
38
39 # Transform the item
40 transformed = self._transform(item)
41
42 # Validate
43 if self._validate(transformed):
44 results.append(transformed)
45
46 return results
47
48 def _transform(self, item: str) -> str:
49 """Transform a single item"""
50 # Convert to lowercase
51 item = item.lower()
52
53 # Remove special characters
54 item = ''.join(c for c in item if c.isalnum() or c.isspace())
55
56 # Trim whitespace
57 item = item.strip()
58
59 return item
60
61 def _validate(self, item: str) -> bool:
62 """Validate an item"""
63 if len(item) < 3:
64 return False
65
66 if not any(c.isalpha() for c in item):
67 return False
68
69 return True
70
71 def save_results(self, output_path: str) -> None:
72 """Save processed results"""
73 with open(output_path, 'w') as f:
74 for item in self.results:
75 f.write(f"{item}\n")
76
77
78def main():
79 """Main entry point"""
80 if len(sys.argv) < 2:
81 print("Usage: python long.py <input_file>")
82 sys.exit(1)
83
84 processor = DataProcessor({"strict": True})
85 processor.load_data(sys.argv[1])
86 results = processor.process()
87
88 print(f"Processed {len(results)} items")
89
90
91if __name__ == "__main__":
92 main()
93
94# Physical LOC: ~95
95# Logical LOC: ~60
96# Comment lines: ~15
97# Blank lines: ~20